From:http://xyzlmn.blog.51cto.com/2532390/1344216
1、布局重用<include />
-
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
-
android:orientation="vertical"
-
android:layout_width=”match_parent”
-
android:layout_height=”match_parent”
-
android:background="@color/app_bg"
-
android:gravity="center_horizontal">
-
-
<includelayout="@layout/titlebar"/>
-
-
<TextViewandroid:layout_width=”match_parent”
-
android:layout_height="wrap_content"
-
android:text="@string/hello"
-
android:padding="10dp"/>
-
-
...
-
-
</LinearLayout>
-
View bookmarks_container_2 = findViewById(R.id.bookmarks_favourite);
-
-
bookmarks_container_2.findViewById(R.id.bookmarks_list);
2、减少视图层级<merge />
-
<mergexmlns:android="http://schemas.android.com/apk/res/android">
-
-
<Button
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:text="@string/add"/>
-
-
<Button
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:text="@string/delete"/>
-
-
</merge>
3、需要时使用<ViewStub />
-
<ViewStub
-
android:id="@+id/stub_import"
-
android:inflatedId="@+id/panel_import"
-
android:layout="@layout/progress_overlay"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:layout_gravity="bottom"/>
-
((ViewStub) findViewById(R.id.stub_import)).setVisibility(View.VISIBLE);
-
// or
-
View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();