首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DrawerLayout双层抽屉(同时放左右两个抽屉)

DrawerLayout双层抽屉(同时放左右两个抽屉)
EN

Stack Overflow用户
提问于 2013-07-25 23:05:24
回答 7查看 62.9K关注 0票数 66

我有一个应用程序,我想在其中实现一个双层抽屉-一个从左,一个从右。左边的抽屉用于应用程序导航,右边的抽屉用于结果过滤。

因此,布局是这样的:

代码语言:javascript
运行
复制
<?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按钮-左边的抽屉也会打开,并与右边的抽屉重叠。

这里有几个我想要的解决方案:

  1. 在右侧制作相同的DrawerToggle按钮,具有与左侧相同的行为和动画。
  2. 在我尝试打开的抽屉的另一侧制作抽屉-自动关闭(如果左侧的抽屉打开,并且我按下右侧抽屉的开关,反之亦然)。

我还没有想好如何做到这一点,因为DrawerToggle接受DrawerLayout本身作为参数,而不是各个抽屉……

我正在使用Support Library。

有谁有什么想法吗?提前谢谢你。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17861755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档