带有两个抽屉的DrawerLayout:当左侧抽屉被打开时,右侧抽屉会“跳动”?

5
我的应用程序有一个DrawerLayout,里面有两个抽屉,一个在左边用于导航,一个在右边用于通知。当应用程序冷启动时,我向左滑动抽屉时,右侧的抽屉从屏幕最左边跳到右边。
它看起来像这样:http://i.imgur.com/mhoJ7MZ.gifv 如视频所示,我尝试使用DrawerLayoutisDrawerOpenisDrawerVisible方法来查看它是否认为右边的抽屉已经打开了(因为似乎在打开左边的抽屉时“关闭”了右边的抽屉),但是我没有得到任何有用的信息。
是什么导致了这种奇怪的跳动?
我的活动XML如下,完整代码在这里
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        ...
    </LinearLayout>

    <LinearLayout
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ACFF0000"
        android:gravity="center"
        android:visibility="gone">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="LEFT DRAWER"
            android:textSize="24sp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/right_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#AC00FF00"
        android:gravity="center"
        android:visibility="gone">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RIGHT DRAWER"
            android:textSize="24sp" />
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>
1个回答

8
问题来自于LinearLayout元素上的android:visibility="gone"属性--由于此属性设置为gone会与DrawerLayout判断视图是否正在显示的逻辑发生冲突,因此它尝试将其隐藏。

从XML中删除该属性会使得所有内容看起来都相同(因为DrawerLayout查看layout_gravity来确定哪些子视图是抽屉(drawer)并自行隐藏),而不会出现奇怪的跳动现象。


测试:这个答案非常棒。 - Brian Nickel

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