1、如果是阅读型文本(例如一篇文章),不需要固定大小的,textSize可以使用sp;如果是展示型文本(例如按钮中的文本),其大小受到限制的,textSize可以使用dp。

2、使用json用作网络数据传输时,应该使用String字段取代int字段。

3、按照现在正常密度比(系统的densityDPI根据分辨率和屏幕尺寸为正常的120、160、240、320、480、640时9:16的安卓机其尺寸为(360dp*540dp)。UI有时会根据iPhone机型使用750px*1334px作图,而按照1dp=2px来算,其结果为(375dp*667dp)。这样放置控件,宽度上会少15dp,高度上会少127dp,如果UI不做图的话,可以根据美观自行处理(通常不应在整个页面的padding上修改尺寸,这个尺寸应该是一开始原型图就规定好的全局样式)。

4、使用GsonFormat插件生成实体类时,整个实体类应放在bean文件夹下。

5、使用Butterknife注解布局时,可以使用Android Butterknife Zelezny插件自动生成注解。

6、需要提交多个模块代码时,按模块多次提交(也方便填写提交信息)。

7、空页面应该有空页面图片提示。

8、支付宝沙箱环境测试,需要在页面启动前添加这么一句代码EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);

9、

[html] view plain copy

  1.     //将字符串转换成Bitmap类型  

  2.   

  3.  public static Bitmap stringtoBitmap(String string){ Bitmap bitmap=null; try { byte[]bitmapArray; bitmapArrayBase64.decode(string, Base64.DEFAULT); bitmapBitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); } catch (Exception e) { e.printStackTrace(); } return bitmap; }  

  4. <span style="font-size:18px;"></span>  

 

10、在完成一个版本上线后,应至少分成两个分支,一个日常修复bug以及紧急上线,另一个用于正常功能开发。

11、如果一个接口不需要传参,应设计为传一个空参(例如new Object()),而不是不传参数,这样方便以后拓展接口。

12、adapter中所有的变化的view或值,都应该在viewholder中定义,并在onBinderView中赋值。

13、预览时选择Project Themes,同时gradle中应使用compile而不是implementation。

电脑培训,计算机培训,平面设计培训,网页设计培训,美工培训,Web培训,Web前端开发培训

14、沉浸式状态栏需要设置主题为

[html] view plain copy

  1. <span style="font-size:18px;">    <!--沉浸式状态栏-->  

  2.     <style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">  

  3.         <!-- Customize your theme here. -->  

  4.         <item name="colorPrimary">@color/colorPrimary</item>  

  5.         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>  

  6.         <item name="colorAccent">@color/colorAccent</item>  

  7.     </style></span>  


另v19设置主题为

 

[html] view plain copy

  1. <span style="font-size:18px;">    <!--沉浸式状态栏-->  

  2.     <style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">  

  3.         <!-- Customize your theme here. -->  

  4.         <item name="colorPrimary">@color/colorPrimary</item>  

  5.         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>  

  6.         <item name="colorAccent">@color/colorAccent</item>  

  7.         <item name="android:windowTranslucentStatus">true</item>  

  8.     </style></span>  


如果还需要使状态栏中的电量等都隐藏,需要在使用的activity代码中设置

 

[html] view plain copy

  1. <span style="font-size:18px;">getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);</span>  

15、进行了某个操作想退出应用,可以使用这样的技巧

 

[html] view plain copy

  1. <span style="font-size:18px;">            //回到桌面  

  2.             Intent intent = new Intent(Intent.ACTION_MAIN);  

  3.             intent.addCategory(Intent.CATEGORY_HOME);  

  4.             intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  

  5.             startActivity(intent);</span>  

16、textview设置滚动,第一步现在XML中设置scrollbars属性,第二步在代码中设置textView.setMovementMethod(ScrollingMovementMethod.getInstance());

17、setOffscreenPageLimit(0)没有效果,最小是1,也就是最小左右各一预加载。

18、调用webview的页面应及时销毁,防止内存泄漏(具体如下):

 

[html] view plain copy

  1. @Override  

  2. protected void onDestroy() {  

  3.     try {  

  4.         if( webView!=null) {  

  5.             ViewParent parent = webView.getParent();  

  6.             if (parent != null) {  

  7.                 ((ViewGroup) parent).removeView(webView);  

  8.             }  

  9.             webView.stopLoading();  

  10.             // 退出时调用此方法,移除绑定的服务,否则某些特定系统会报错  

  11.             webView.getSettings().setJavaScriptEnabled(false);  

  12.             webView.clearHistory();  

  13.             webView.clearView();  

  14.             webView.removeAllViews();  

  15.             webView.destroy();  

  16.         }  

  17.     } catch (Exception e) {  

  18.         e.printStackTrace();  

  19.     }  

  20.     super.onDestroy();  

  21. }  

19、WebView的一些相关设置

 

[html] view plain copy

  1. WebSettings webSettings = webView.getSettings();  

  2.   

  3. //支持获取手势焦点,输入用户名、密码或其他  

  4. webView.requestFocusFromTouch();  

  5.   

  6. webSettings.setJavaScriptEnabled(true);  //支持js  

  7. //webSettings.setPluginsEnabled(true);  //支持插件  

  8.   

  9. //设置自适应屏幕,两者合用  

  10. webSettings.setUseWideViewPort(true);  //将图片调整到适合webview的大小  

  11. webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小  

  12.   

  13.   

  14. webSettings.setSupportZoom(true);  //支持缩放,默认为true。是下面那个的前提。  

  15. webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。  

  16. //若上面是false,则该WebView不可缩放,这个不管设置什么都不能缩放。  

  17.   

  18. webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件  

  19.   

  20. webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持内容重新布局  

  21. webSettings.supportMultipleWindows();  //多窗口  

  22. webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);  //关闭webview中缓存  

  23. webSettings.setAllowFileAccess(true);  //设置可以访问文件  

  24. webSettings.setNeedInitialFocus(true); //当webview调用requestFocus时为webview设置节点  

  25. webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口  

  26. webSettings.setLoadsImagesAutomatically(true);  //支持自动加载图片  

  27. webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式  

  28. //允许自动播放多媒体  

  29. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {  

  30.     webSettings.setMediaPlaybackRequiresUserGesture(false);  

  31. }  

  32.   

  33. //从Android5.0开始,WebView默认不支持同时加载Https和Http混合模式  

  34. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {  

  35.     webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);  

  36. }  

20、scrollView设置android:fillViewport="true",使scrollview的子控件能够充满屏幕。

21、gradle编译报错

 

[html] view plain copy

  1. Error:Failed to open zip file.  

  2. Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)  

  3. <a href="syncProject">Re-download dependencies and sync project (requires network)</a>  

  4. <a href="syncProject">Re-download dependencies and sync project (requires network)</a>  

Windows下需要打开AndroidStudio的Files——>Settings——>Build...——>Gradle,手动设置gradle位置。

22、将弹出的软键盘的回车键改为搜索键

 

[html] view plain copy

  1. <EditText  

  2.     android:id="@+id/et_search"  

  3.     android:layout_width="match_parent"  

  4.     android:layout_height="match_parent"  

  5.     android:imeOptions="actionSearch"  

  6.     android:singleLine="true"  

  7.     android:inputType="text"/>  

其中android:imeOptions需要配合android:inputType属性(或者singleLine属性,PS:单独设置maxLines并不能解决问题)才能使回车键变为需要的图标。

[html] view plain copy

  1. etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {  

  2.     @Override  

  3.     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {  

  4.         if (actionId == EditorInfo.IME_ACTION_SEARCH) {  

  5.             initData();  

  6.             return true;  

  7.         }  

  8.         return false;  

  9.     }  

  10.   

  11. });