我有一個應用程序,我想在其中實現一個雙抽屜-一個在左邊,另一個在右邊。左抽屜用于應用程序導航,右抽屜用于結果過濾。因此,布局如下所示:<?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”,以及它們各自的重力-“開始”和“結束”,這實際上有效!您可以將它們全部拉出。問題是,當我實現DrawerToggle時-它僅打開左抽屜,而沒有關閉右抽屜,因此,如果右抽屜被打開并且我按DrawerToggle按鈕-左抽屜也將打開,并且與右抽屜重疊。我正在嘗試幾種解決方案:在右側創建相同的DrawerToggle按鈕,其行為和動畫與左側相同。將抽屜放在我要打開的抽屜的另一側-自動關閉(如果左抽屜打開并且我按下右抽屜的扳鈕,反之亦然)。而且我還沒有弄清楚該怎么做,因為DrawerToggle接受DrawerLayout本身作為參數,而不是單個抽屜...我正在使用支持庫。有人有想法么?先感謝您。
3 回答

慕標琳琳
TA貢獻1830條經驗 獲得超9個贊
您可以在ToggleButton的處理程序中這樣調用它,例如:
mDrawerLayout.openDrawer(mDrawer);
mDrawerLayout.closeDrawer(mDrawer);
其中mDrawer是對您需要打開的特定抽屜(是視圖還是布局)的引用,在這種情況下,是您希望顯示的實際ListView。
- 3 回答
- 0 關注
- 769 瀏覽
添加回答
舉報
0/150
提交
取消