android sdk提供了对Android项目布局的优化分析工具layoutopt命令。例如:我的项目,在workspace下,
首 先,进入sdk的tools目录下,输入命令layoutopt+项目目录(例如,xp环境下为C:/workspace/;Linux环境下为 workspace/)+工程名字+res+layout+(这里可继续到指定的目录下,也可以指定具体的xml文件,也可以不写)
例子:
这是我在xp环境下,运行layoutopt命令检查C:/workspace/android.welcomeDemo/res/layout/目录下两个xml文件。
8:17 This LinearLayout layout or its LinearLayout parent is useless表示的意思第8行,提示未使用到的布局 ;
15:15 Use an android:layout_height of 0dip instead of wrap_content for better performance表示的意思是第15行,android:layout_height最好使用0dip替换掉之前的wrap_content 。
<ListView android:id="@+id/list" android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="10"
android:drawSelectorOnTop="true" />
还有一些常见的:
7:23 The root-level <FrameLayout/> can be replaced with <merge/>提示建议替换标签
-1:-1 This layout has too many nested layouts: 13 levels, it should have <= 10!提示过多的嵌套布局
-1:-1 This layout has too many views: 81 views, it should have <= 80! samples/useless.xml提示在一个布局中过多的视图组件。
更多详细信息:http://androidappdocs.appspot.com/guide/developing/tools/layoutopt.html
[pre]$ layoutopt samples /
samples / compound . xml
7 : 23 The root - level < FrameLayout /> can be replaced with < merge />
11 : 21 This LinearLayout layout or its FrameLayout parent is useless
samples / simple . xml
7 : 7 The root - level < FrameLayout /> can be replaced with < merge />
samples / too_deep . xml
- 1 :- 1 This layout has too many nested layouts : 13 levels , it should have <= 10 !
20 : 81 This LinearLayout layout or its LinearLayout parent is useless
24 : 79 This LinearLayout layout or its LinearLayout parent is useless
28 : 77 This LinearLayout layout or its LinearLayout parent is useless
32 : 75 This LinearLayout layout or its LinearLayout parent is useless
36 : 73 This LinearLayout layout or its LinearLayout parent is useless
40 : 71 This LinearLayout layout or its LinearLayout parent is useless
44 : 69 This LinearLayout layout or its LinearLayout parent is useless
48 : 67 This LinearLayout layout or its LinearLayout parent is useless
52 : 65 This LinearLayout layout or its LinearLayout parent is useless
56 : 63 This LinearLayout layout or its LinearLayout parent is useless
samples / too_many . xml
7 : 413 The root - level < FrameLayout /> can be replaced with < merge />
- 1 :- 1 This layout has too many views : 81 views , it should have <= 80 !
samples / useless . xml
7 : 19 The root - level < FrameLayout /> can be replaced with < merge />
11 : 17 This LinearLayout layout or its FrameLayout parent is useless [/pre]
layoutopt用法
最新推荐文章于 2024-07-13 23:11:02 发布