【发布时间】:2011-05-02 02:11:32
【问题描述】:
我想将我的 UI 分解为几个 XML 布局。第一个是主布局,另一个是内容布局。
我希望能够设置在运行时动态包含哪个 content_layout,所以我不想在我的 XML 文件中设置 "layout="@+layout/content_layout"。
这是我的布局:
main_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="600dp"
android:layout_height="800dp" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<include /> <!-- I WANT TO INCLUDE MY CONTENT HERE -->
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Cancel" />
</RelativeLayout>
content_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/whatever"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
content_layout2.xml:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/whatever2"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
我该怎么做?
谢谢!
【问题讨论】:
标签: android layout android-layout include