Android——Android lint工具項目資源清理詳解_Android

來源:互聯網
上載者:User

Android——Android lint工具項目資源清理

最近維護的項目已經有兩年多,經過很多前輩的迭代,項目並沒有變得健壯,而變得很臃腫.用Android lint工具清理了一次,清楚了不少廢棄的布局和資源.

1.     Android lint工具

可以右鍵項目,Android tools,退出的時候clear lint markers即可


也可以如圖:


2.結果出來了,分析分析


3.xml中view太多,已經超過了80個,影響效能.

布局最佳化:

盡量使用include、merge、ViewStub標籤,盡量不存在冗餘嵌套及過於複雜布局,盡量使用GONE替換INVISIBLE,使用weight後盡量將width和heigh設定為0dp減少運算,Item存在非常複雜的嵌套時考慮使用自訂Item View來取代,減少measure與layout次數等。

 列表及Adapter最佳化;盡量複用getView方法中的相關View,不重複擷取執行個體導致卡頓,列表盡量在滑動過程中不進行UI元素重新整理等。

背景和圖片等記憶體配置最佳化;盡量減少不必要的背景設定,圖片盡量壓縮處理顯示,盡量避免頻繁記憶體抖動等問題出現。

自訂View等繪圖與布局最佳化;盡量避免在draw、measure、layout中做過於耗時及耗記憶體操作,尤其是draw方法中,盡量減少draw、measure、layout等執行次數。 

避免ANR,不要在UI線程中做耗時操作,遵守ANR規避規則,譬如多次資料庫操作等。

activity_group_number_detail1.xml has more than 80 views, bad for performance

Issue: Checks whether a layout has too many views

Id: TooManyViews

Using too many views in a single layout is bad for performance. Consider using compound drawables or other tricks for reducing the number of views in this layout.


4.沒有定義的id,刪掉就ok

he id "top" is not defined anywhere.

Issue: Checks for id references in RelativeLayouts that are not defined elsewhere

Id: UnknownId


5.同一個XML重複定義id

在同個一個Xml檔案的中如果ID同名,則前一個有效,而後一個無效

是不是複製粘貼的時候出錯了?

Duplicate id @+id/group_imageView2, already defined earlier in this layout

Issue: Checks for duplicate ids within a single layout

Id: DuplicateIds


6.ID的引用不在同一級layout中,比如說:控制項A在B(B是viewgroup)的下面,而不應該寫成A在B的子控制項下面.



7.廢棄的四大組件,在mainfest.xml中沒有清掉.刪除就ok

Class referenced in the manifest, com.baidu.location.f, was not found in the project or the libraries

Issue: Ensures that classes referenced in the manifest are present in the project or libraries

Id: MissingRegistered


8.沒使用的資源,這是重頭戲,對於減小包的大小很有意義.其中包含了xml,dimens等.量比較大,建議先提交SVN之後再刪除,如果出了問題立馬可以還原.

The resource R.drawable.fc_seekbar_thumb appears to be unused

Issue: Looks for unused resources

Id: UnusedResources

9.這裡檢測的結果只是提供一種參考,建議用Toast.LENGTH_SHORT或者 Toast.LENGTH_LONG


10.硬式編碼問題,使用Context.getFilesDir().getPath()

Do not hardcode "/data/"; use Context.getFilesDir().getPath() instead

Issue: Looks for hardcoded references to /sdcard

Id: SdCardPath

Your code should not reference the /sdcard path directly; instead use Environment.getExternalStorageDirectory().getPath().


11.大家一看就懂了,viewholder的問題



12.handler導致的記憶體流失問題

一兩句話說不清,下面是已經說清楚的.

http://blog.csdn.net/lijunhuayc/article/details/47999931


13.webview的父控制項,寬高建議用match_parent

提示

  Placing a <WebView> in a parent element that uses a wrap_content layout_height can lead to subtle 
 bugs; use match_parent instead  

14.I18N的問題就不說了.

總結:Android lint工具主要功能是規範編碼,最佳化布局效能,去除無用資源.

感謝閱讀,希望能協助到大家,謝謝大家對本站的支援!


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.