[英]Android re-use XML layout
How can I name an XML layout and use it in another layout? 如何命名XML布局并在其他布局中使用它? Let's say I have the following defined:
假设我有以下定义:
<ImageView
android:id="@+id/drawer_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/drawer_itemName"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
and I want to call this Avatar so in another XML I can do like this: 我想称呼这个头像,所以在另一个XML中我可以这样:
<LinearLayout
android:id="@+id/itemLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<Avatar /> <!-- THIS -->
</LinearLayout>
Look at the <include/>
tag. 查看
<include/>
标记。
http://developer.android.com/training/improving-layouts/reusing-layouts.html http://developer.android.com/training/improving-layouts/reusing-layouts.html
您可以使用include
标记重复使用布局:
<include layout="@layout/Avatar"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.