<merge>
thẻ được sử dụng để giảm thiểu số lượng các cấp độ để tăng hiệu suất của bố trí rendering. thẻ được sử dụng với thẻ <include>
hoàn hảo cùng nhau.
Lấy ví dụ, chúng tôi có bố cục đăng nhập và được sử dụng cho nhiều hơn một phạm vi trong ứng dụng của chúng tôi. Trong khi sử dụng thẻ để hiển thị login_layout, chúng tôi có thể sử dụng và có thể thoát khỏi một cấp độ.
Tôi cũng khuyên bạn nên đọc các mẹo về bố cục. http://android-developers.blogspot.com.tr/2009/03/android-layout-tricks-3-optimize-by.html
login_form.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Login form -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email..."
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"
android:visibility="visible" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password.."
android:imeActionId="@+id/login"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:text="1337"
android:visibility="visible" />
<Button
android:id="@+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16sp"
android:paddingLeft="32sp"
android:paddingRight="32sp"
android:text="Login"
android:visibility="visible" />
</LinearLayout>
example_layout.xml (bất kỳ bố trí chúng tôi muốn bao gồm login_form.xml)
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<include layout="@layout/login_form" />
</merge>
Chúng ta có thể thấy hệ thống phân cấp mức
Vui lòng xem phần tắt tài liệu hướng dẫn về icial Android: [Tái sử dụng Bố cục với ] (http://developer.android.com/training/improving-layouts/reusing-layouts.html) –
JJD
http://stackoverflow.com/a/11093340/596555, có thể giúp u. – boiledwater
FYI, nếu bạn đang tìm cách sử dụng điều này với ** menu **, bạn đã hết may mắn, nhưng bạn có thể thổi phồng nhiều tệp XML, như được mô tả ở đây: http: // stackoverflow.com/questions/4337034/include-menu-in-menu-android –