我没有一个Android的布局文件activity_item_list.xml,其内容如下列表:如何<include>带有片段标签的布局文件?
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_list"
android:name="xxx.xxx.xxx.ItemListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context=".ItemListActivity"
tools:layout="@android:layout/list_content" />
那么,它会崩溃。崩溃日志低于:
android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
我将列出这里所有的步骤:
在Eclipse中,通过向导并选择主/新项目流
向导结束后,我获得了4个由向导生成的布局xmls:activity_item_detail.xml,activity_item_twopane.xml,activity_item_list.xml和fragment_item_detail.xml
让我们修改activity_item_twopane.xml。我想重新使用一些布局。
的一部开拓创新activity_item_twopane.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".ItemListActivity" >
<fragment
android:id="@+id/item_list"
android:name="xxx.xxx.xxx.ItemListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@android:layout/list_content" />
<FrameLayout
android:id="@+id/item_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
修改后的文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".ItemListActivity" >
<include
layout="@layout/activity_item_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<include
layout="@layout/activity_item_detail"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"/>
</LinearLayout>
现在,第二个包括块效果很好。但第一个会导致崩溃。
activity_item_detail.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" />
而且我试过如下修改activity_item_list.xml,还是死机....
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/item_list"
android:name="xxx.xxx.xxx.ItemListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context=".ItemListActivity"
tools:layout="@android:layout/list_content" />
</FrameLayout>
我不知道为什么机器人不能支持一个片段。谁可以告诉我。谢谢!
以及如何在您的布局使用它吗? – waqaslam 2013-03-26 08:28:35
请看我的新帖子。谢谢! – paranoia 2013-03-26 09:26:42
你也可以粘贴xml for activity_item_detail吗? – waqaslam 2013-03-26 09:30:54