Optimize the layout hierarchy 1. Avoid layout tessellation too deep (see below)
<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:layout_height="Match_parent"tools:context=". Mainactivity "> <linearlayout android:id="@+id/main_ll_duoyu"Android:layout_width="Match_parent"android:layout_height="Match_parent"> <textview android:text="@string/hello_world"Android:layout_width="Wrap_content"android:layout_height="Wrap_content"/> <linearlayout android:layout_width="Match_parent"android:layout_height="Match_parent"android:gravity="Center_horizontal"android:layout_gravity="Center_vertical"> <textview android:text="@string/hello_world"Android:layout_width="Wrap_content"android:layout_height="Wrap_content"/> </LinearLayout> </LinearLayout></LinearLayout>
We can completely remove the ID: main_ll_duoyu
This linearlayout can also achieve the effect we want (the effect is as follows)
2. Use tools to view layouts
Sdk\tools\hierarchyviewer.bat | Double-click Open
We have now removed main_ll_duoyu
this linearlayout, we are a little bit less than the first two graphs and the most one, here is just an example, you can use these tools provided by Google to help us optimize the app, to increase the flow of user experience
3. Default maximum layout depth
Android default to the layout depth of 10
Android optimized--ui optimization (i)