【发布时间】:2021-09-11 09:24:01
【问题描述】:
根据 Google 的导航抽屉Material Design guideline,要在平板电脑或桌面设备上实现Standard drawer,我会在平板设备上使用 NavigationView 和 SlidingPaneLayout,而不是在手机设备上使用 DrawerLayout,即实现Modal drawer。
我将 NavigationView 作为 SlidingPaneLayout 的第一个子视图。出现问题。
如您所知如果SlidingPaneLayout 的子视图的组合宽度超过SlidingPaneLayout 中的可用宽度,则它们会重叠。在这种情况下,子视图会展开以填充 SlidingPaneLayout 中的可用宽度。用户可以通过从屏幕边缘向后拖动来将最顶部的视图滑开。
但我的 NavigationView 的窗格不会滑动。它只是以最大宽度出现或消失,没有滑动动画。
我该如何解决这个问题?
<androidx.slidingpanelayout.widget.SlidingPaneLayout
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"
tools:context=".MainActivity">
<!-- The first child view becomes the left pane. When the combined
desired width (expressed using android:layout_width) would
not fit on-screen at once, the right pane is permitted to
overlap the left. -->
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigationView"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_view_header"
app:menu="@menu/navigation_view" />
<!-- The second child becomes the right (content) pane. In this
example, android:layout_weight is used to expand this detail pane
to consume leftover available space when the
the entire window is wide enough to fit both the left and right pane.-->
<fragment
android:id="@+id/navigationHost"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="320dp"
android:layout_weight="1"
android:layout_height="match_parent"
app:navGraph="@navigation/main" />
</androidx.slidingpanelayout.widget.SlidingPaneLayout>
【问题讨论】:
标签: android android-layout material-design navigation-drawer