【发布时间】:2016-07-14 07:20:36
【问题描述】:
我在我的 android 应用程序上实现了一个导航抽屉,并且工作正常。但我现在的问题是,我的导航抽屉中的菜单变得很长,底部菜单位于导航栏下方。如何将导航抽屉放在导航栏顶部? Lollipop 和 Marshmallow 的行为相同。
请在下面找到截图。
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:elevation="8dp"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="@+id/container_body"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/fragment_song_list_main" />
</FrameLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/fragment_navigation_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
-
但是您的 NavigationView 的列表不是可滚动的吗?我在 Android Studio 的 Navigation Drawer 模板上进行了测试,似乎当列表很长时,它变成了可滚动的,您必须滚动它才能看到最新的元素。
-
@Laura 它是可滚动的,最后一个菜单是“设置”,如上图所示。当您滚动时,它会出现在设置中和导航栏下方。
-
可能是主题问题。您的应用或活动主题是否具有以下 2 个属性:
- false
- true
。你也可以看看这个教程myandroidsolutions.com/2016/07/13/android-navigation-view-tabs。也许它会帮助你。
标签: android android-layout navigation-drawer navigationbar