DrawerLayout双抽屉(左和右抽屉同时)抽屉、DrawerLayout

2023-09-11 20:28:26 作者:沉默就是答案,躲闪就是答案,不再主动就是答案,其实,你早就该

我有一个应用程序,其中我想实现一个双抽屉里 - 一个来自左边,一个在右边。左抽屉的应用程序导航,右边抽屉的结果进行过滤。

I have an application, in which i want to implement a double drawer - one from the left and one from the right. Left drawer is for app navigation, right drawer is for result filtering.

因此​​,布局是这样的:

So, the layout is like this:

<?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:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:background="@color/light_grey"
            >
        <GridView android:id="@+id/gridview"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:verticalSpacing="7dp"
                  android:horizontalSpacing="7dp"
                  android:stretchMode="columnWidth"
                  android:gravity="center"
                  style="@style/GridViewStyle"/>
    </LinearLayout>
    <ListView android:id="@+id/left_drawer"
              android:layout_width="240dp"
              android:layout_height="match_parent"
              android:layout_gravity="start"
              android:choiceMode="singleChoice"
              android:divider="@android:color/transparent"
              android:dividerHeight="0dp"
              android:background="#111"/>
    <ListView android:id="@+id/right_drawer"
              android:layout_width="240dp"
              android:layout_height="match_parent"
              android:layout_gravity="end"
              android:choiceMode="singleChoice"
              android:divider="@android:color/transparent"
              android:dividerHeight="0dp"
              android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

您可以清楚地看到这里的left_drawer和right_drawer,以及它们各自的严重性 - 开始和结束 而这种实际工作!你可以拉他们两个。

You can clearly see here "left_drawer" and "right_drawer", and their respective gravity - "start" and "end" And this actually works! You can pull them both out.

现在的问题是,当我实现了DrawerToggle - 只打开左边的抽屉里,并没有关闭正确的,所以如果有合适的抽屉被打开,我preSS的DrawerToggle按钮 - 左边抽屉打开。另和重叠右抽屉。

The problem is, when i implement the DrawerToggle - it only opens the left drawer, and does not close the right one, so if the right drawer is opened and i press the DrawerToggle button - the left drawers opens ALSO, and overlaps the right drawer.

有几个解决方案我'试图获得:

There are a couple of solutions i'am trying to get:

请右侧相同DrawerToggle按钮,与作为左侧相同的行为和动画。 请抽屉抽屉我试图打开的另一侧 - 自动关闭(如果左边抽屉是打开的,我preSS正确的抽屉,反之亦然的切换)

和我还没有想出如何做到这一点,因为DrawerToggle接受DrawerLayout本身作为一个参数,而不是单独的抽屉......

And i haven't figured how to do that, because DrawerToggle accepts the DrawerLayout itself as a parameter, and not the individual drawers...

我使用的是支持库。

任何人有什么想法? 谢谢你在前进。

Anyone have any ideas? Thank you in advance.

推荐答案

您可以调用它的切换按钮的处理程序,例如:

You can call it like this in a ToggleButton's handler for example :

mDrawerLayout.openDrawer(mDrawer);
mDrawerLayout.closeDrawer(mDrawer);

在哪里mDrawer是一个参考,你需要打开特定的抽屉(无论是一个视图或布局),你的情况,实际的ListView要显示。

Where mDrawer is a reference to the specific drawer you need to open (be it a view or a layout), in your case, the actual ListView you wish to display.