如何禁用只有右侧导航栏的滑动?

14

我在我的Activity中有两个导航抽屉,分别位于两侧。我不需要通过滑动手势打开右侧的导航抽屉。

如果我使用:

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)

要锁定滑动,则左右两个抽屉都被锁定。但我想左边的抽屉能够检测到滑动手势。我该如何做到这一点?

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="left" />

    <ListView
        android:id="@+id/right_drawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="right" />

</android.support.v4.widget.DrawerLayout>

1
请参见此处:https://dev59.com/Gnvaa4cB1Zd3GeqPEIMz#21233786 - Gopal Gopi
使用相同的函数setDrawerLockMode并添加一个参数来实现 mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, findViewById(R.id.right_drawer)); - DevAndroid
1个回答

31
使用相同的函数setDrawerLockMode,加上一个额外的参数即可实现。
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, findViewById(R.id.right_drawer));

我尝试过这个,如果右边的抽屉已经打开,而你从左边滑动,那么左边的抽屉也会打开。 >.> - EpicPandaForce

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接