Android 活动中的菜单未溢出片段

Android 活动中的菜单未溢出片段,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,问题:我创建了包含抽屉和框架布局的活动,这些活动将被碎片膨胀 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools=

问题:我创建了包含抽屉和框架布局的活动,这些活动将被碎片膨胀

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">


    <FrameLayout
        android:id="@+id/main_fragment_panel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!-- The navigation drawer -->
    <RelativeLayout
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:id="@id/drawerPanel"
        android:layout_gravity="start"
        android:background="@color/backgroundColor">

        <-- CONTENT->>
    </RelativeLayout>





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

>
将片段更改/膨胀为FrameLayout主\u fragment\u面板后,抽屉应该打开(日志中的所有内容看起来都很好),但看起来片段溢出了活动中的所有内容。如何更改布局的“级别”或“优先级”?
更新:我已经更新了上面的代码-它现在显示正确,但没有处理来自的任何事件(那里有一些带有侦听器的按钮)

请尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <fragment
        android:id="@+id/right_drawer"
        android:name="com.fragments.RightFragment"//your left fragment
        android:layout_width="@dimen/drawer_width"
        android:layout_height="fill_parent"
        android:layout_gravity="left" />
</android.support.v4.widget.DrawerLayout>

尝试以下方法:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <fragment
        android:id="@+id/right_drawer"
        android:name="com.fragments.RightFragment"//your left fragment
        android:layout_width="@dimen/drawer_width"
        android:layout_height="fill_parent"
        android:layout_gravity="left" />
</android.support.v4.widget.DrawerLayout>

您应该使用抽屉布局作为父布局。修订后的守则如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

     <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        android:background="@color/background_material_dark"
        app:itemTextColor="@color/colorWhite"
        app:menu="@menu/activity_main_drawer" />

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

您应该使用抽屉布局作为父布局。修订后的守则如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

     <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        android:background="@color/background_material_dark"
        app:itemTextColor="@color/colorWhite"
        app:menu="@menu/activity_main_drawer" />

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

您的抽屉布局应如下所示

 <?xml version="1.0" encoding="utf-8"?>
<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 -->

    <LinearLayout
        android:id="@+id/llContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <!-- The navigation drawer -->
    <!-- Menu items--->
    <android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:background="@drawable/background_drawer"
    app:headerLayout="@layout/nav_header"
    app:itemIconTint="@color/colorPrimary"
    app:menu="@menu/menu_navigation" />

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

你的抽屉布局应该是这样的

 <?xml version="1.0" encoding="utf-8"?>
<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 -->

    <LinearLayout
        android:id="@+id/llContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <!-- The navigation drawer -->
    <!-- Menu items--->
    <android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:background="@drawable/background_drawer"
    app:headerLayout="@layout/nav_header"
    app:itemIconTint="@color/colorPrimary"
    app:menu="@menu/menu_navigation" />

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

将FrameLayout放入抽屉布局标签谢谢@tahsinRupam。请分开邮寄,以便我可以标记为答案;)顺便说一句,现在菜单中的项目是不可点击的:(我已经编辑了我的答案。让我知道这是否有效:)将FrameLayout放入抽屉布局标记Thank you@tahsinRupam。请分开邮寄,以便我可以标记为答案;)顺便说一句,现在菜单中的项目是不可点击的:(我已经编辑了我的答案。请让我知道这是否有效:)这非常有效,但菜单中没有处理任何事件:(单击某个菜单项后,它将关闭抽屉。我现在必须离开我的办公室。我将在到家时给出修改后的答案。和我在一起:pits正在工作!我做了一些奇怪的事情!谢谢!这非常有效,但菜单中的任何事件都没有得到处理:(单击某个菜单项后,它会关闭抽屉。我现在必须离开我的办公室。我会在到家后给出修改后的答案。和我在一起:坑正在工作!我做了一些奇怪的事情!谢谢!虽然我很喜欢NavigationView的想法,但在设计方面,我有一个非常不寻常的菜单,我想远离它。)om NavigationView。我已经更新了原始问题-现在它的打开正确,但没有事件:(虽然我非常喜欢NavigationView的想法,但在设计方面,我有一个非常不寻常的菜单,我想远离NavigationView。我已经更新了原始问题-现在它正确地打开了,但没有任何事件:(