【发布时间】:2013-07-25 13:35:58
【问题描述】:
我有一个应用程序,我想在其中实现一个双抽屉 - 一个来自左侧,一个来自右侧。左抽屉用于应用导航,右抽屉用于结果过滤。
所以,布局是这样的:
<?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">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_grey"
android:orientation="vertical">
<GridView
android:id="@+id/gridview"
style="@style/GridViewStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:horizontalSpacing="7dp"
android:stretchMode="columnWidth"
android:verticalSpacing="7dp" />
</LinearLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
<ListView
android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
您可以在这里清楚地看到“left_drawer”和“right_drawer”,以及它们各自的重力——“start”和“end” 这确实有效!你可以把它们都拉出来。
问题是,当我实现 DrawerToggle 时 - 它只打开左侧抽屉,而不关闭右侧抽屉,所以如果打开右侧抽屉并且我按下 DrawerToggle 按钮 - 左侧抽屉也打开,并且重叠右边的抽屉。
我想得到几个解决方案:
- 在右侧制作相同的 DrawerToggle 按钮,其行为和动画与左侧相同。
- 将抽屉放在我尝试打开的抽屉的另一侧 - 自动关闭(如果左侧抽屉打开并且我按下右侧抽屉的开关,反之亦然)。
我还没想好怎么做,因为 DrawerToggle 接受 DrawerLayout 本身作为参数,而不是单个抽屉...
我正在使用支持库。
有人有什么想法吗? 提前谢谢你。
【问题讨论】:
标签: android navigation-drawer drawerlayout