Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-layout在两个独立的文件中定义?_Android_Xml_Layout_Styles - Fatal编程技术网

Android-layout在两个独立的文件中定义?

Android-layout在两个独立的文件中定义?,android,xml,layout,styles,Android,Xml,Layout,Styles,我发现我的活动的布局是在两个文件中定义的。这是/res/menu中的my main.xml: <menu xmlns:android="http://schemas.android.com/apk/res/android" > <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:

我发现我的活动的布局是在两个文件中定义的。这是/res/menu中的my main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- The main content view -->
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- The navigation drawer -->
        <ListView android:id="@+id/left_drawer"
            style="@style/NavigationDrawer"/>

            <!--  android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#111"/> -->

    </android.support.v4.widget.DrawerLayout>


    <item
        android:id="@+id/add_button"
        android:icon="@drawable/ic_action_new"
        android:title="@string/add_button"
        android:showAsAction="ifRoom"/>

</menu>

在这里,您可以在/res/layout/子文件夹中找到我的activity_main.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg">


    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        style="@style/NavigationDrawer"/>
</android.support.v4.widget.DrawerLayout>


如您所见,例如,导航抽屉定义了两次。有必要吗?我是否必须将每次更改都写入这两个文件?

从main.xml中删除以下内容。如果在布局文件中进行更改,则无需在main.xml中进行任何更改

查看下面的链接查看布局。
activity\u main.xml
是一个布局文件

main.xml
是一种菜单资源



嗯,这似乎合乎逻辑。不知道如何将所有这些添加到菜单资源。@user2971688您不需要将所有这些添加到菜单资源。检查MyPost中的链接您是否可以重复使用包含抽屉布局的布局?看-
<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- The main content view -->
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- The navigation drawer -->
        <ListView android:id="@+id/left_drawer"
            style="@style/NavigationDrawer"/>

            <!--  android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#111"/> -->

    </android.support.v4.widget.DrawerLayout>