Android 安卓系统:<;包括/>;布局在景观中的应用

Android 安卓系统:<;包括/>;布局在景观中的应用,android,android-layout,Android,Android Layout,我尝试在横向模式下使用include标记重用activity_main.xml和contact_details.xml中的布局代码。我想在左侧显示活动主界面,在右侧显示联系人详细信息。但当我切换到横向模式时,应用程序崩溃 这是activity_main.xml的编码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" andro

我尝试在横向模式下使用include标记重用activity_main.xml和contact_details.xml中的布局代码。我想在左侧显示活动主界面,在右侧显示联系人详细信息。但当我切换到横向模式时,应用程序崩溃

这是activity_main.xml的编码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/list_data"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<Button
    android:id="@+id/btnAddContact"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_weight="0"
    android:text="Add Contact" />

</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

<include layout="@layout/activity_main"/>
<View
    android:layout_width="1dp"
    android:layout_height="fill_parent"
    android:background="#A3A3A3"/>

<include layout="@layout/contact_details"/>

</LinearLayout>

这是contact_details.xml的编码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/lvContactDetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

这是我的布局land/activity_main.xml的编码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/list_data"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<Button
    android:id="@+id/btnAddContact"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_weight="0"
    android:text="Add Contact" />

</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

<include layout="@layout/activity_main"/>
<View
    android:layout_width="1dp"
    android:layout_height="fill_parent"
    android:background="#A3A3A3"/>

<include layout="@layout/contact_details"/>

</LinearLayout>


解决这个问题有什么建议吗?提前感谢。

在您的活动\u main.xml中,联系您正在使用的\u details.xml

android:layout\u width=“fill\u parent”

相反,尝试使用

android:layout_width="wrap_content"

如果您没有发布日志猫报告

感谢Adinia的建议。这是因为我不应该调用相同的布局名称,即activity_main.xml。这是坠机的主要原因。正如阿迪尼亚所说,这可能是一个循环引用。再次感谢。顺便说一下,我只允许在2天内接受我的答案。

使用LogCat检查与“崩溃”相关的堆栈跟踪。更改要包含的布局的名称,不要将其命名为activity\u main;这可能是循环引用。@Adinia谢谢。你解决了我的问题!这不是撞车的原因;最糟糕的情况是,布局看起来不会像预期的那样。@Adinia我想你是对的。但是我有一个问题,xml是否有不同的R值?如果是,那么der使用相同的名称是没有问题的?请纠正我如果在横向中有错,系统只知道一个activity_main.xml文件,因此试图将其包含在其中会崩溃;您无意告诉它您想从默认文件夹访问文件。所以使用layout land/activity\u main.xml不会有帮助吗?