如何在Android中包含布局?
我正在创建通用布局。我想在另一个页面中包含该布局。
发布于 2014-04-10 03:34:54
请注意,如果将android:id...
包含在<include />
标记中,它将覆盖在包含的布局中定义的任何id。例如:
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/some_id_if_needed"
layout="@layout/yourlayout" />
yourlayout.xml:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/some_other_id">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/button1" />
</LinearLayout>
然后,您可以在代码中引用此包含的布局,如下所示:
View includedLayout = findViewById(R.id.some_id_if_needed);
Button insideTheIncludedLayout = (Button)includedLayout.findViewById(R.id.button1);
发布于 2011-04-12 16:04:44
使用<include />
标签。
<include
android:id="@+id/some_id_if_needed"
layout="@layout/some_layout"/>
发布于 2014-08-21 15:46:14
尝尝这个
<include
android:id="@+id/OnlineOffline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
layout="@layout/YourLayoutName" />
https://stackoverflow.com/questions/5632114
复制相似问题