Android 全屏导航抽屉
我有一个像这样的导航抽屉 我想做的是把抽屉打开到全屏而不是半屏。 如何使这个抽屉全屏打开 这是抽屉布局的xmlAndroid 全屏导航抽屉,android,navigation-drawer,drawerlayout,Android,Navigation Drawer,Drawerlayout,我有一个像这样的导航抽屉 我想做的是把抽屉打开到全屏而不是半屏。 如何使这个抽屉全屏打开 这是抽屉布局的xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include
android:id="@+id/toolbar_layout"
layout="@layout/app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar_layout"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="@+id/activityMainContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<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:background="@color/colorPrimary"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:itemTextColor="@android:color/white"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
您必须将
抽屉布局作为xml
中的主布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar_layout"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include
android:id="@+id/toolbar_layout"
layout="@layout/app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/activityMainContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<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:background="@color/colorPrimary"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:itemTextColor="@android:color/white"
app:menu="@menu/activity_main_drawer" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
尝试将android:layout\u width=“wrap\u content”
更改为android:layout\u width=“fill\u parent”
这将解决您的问题,并让我知道……试试这个希望它能起作用:
<include
android:id="@+id/left_drawer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
layout="@layout/drawer"
android:layout_marginLeft="-64dp"/>
您可以尝试此导航视图
属性100%工作
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:layout_marginEnd="-65dp"
android:layout_marginRight="-65dp"
app:itemTextColor="@color/lightgray"
app:itemIconTint="@color/colorAccent"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
这就是您可以实现它的方法
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginEnd="-65dp"
android:layout_marginRight="-65dp"
android:fitsSystemWindows="true">
/>
/>
在主抽屉布局类中,变量如下
private static final int MIN\u DRAWER\u MARGIN=64代码>
因此,要使抽屉装满,只需将android:layout_margintart=“-64dp”
提供给导航视图或将装入抽屉的容器即可 这样做将把我的工具栏放在抽屉里,也就是说,它不会像图片中那样位于顶部,这不是我的要求。我希望工具栏保持在抽屉布局上方,并将侧抽屉打开到全屏而不是半屏。尝试了此解决方案,但仍然无法覆盖整个屏幕。某些部分仍被遗漏。填充父项不推荐使用。navigationview宽度匹配父项在使用剩余大小封面后-使用65页边距。对不起,英语不好。