抽屉有两个抽屉的布局:打开左边一个"jumping"右边的抽屉?



我的应用程序有一个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>

问题来自LinearLayout上的android:visibility="gone"元素——由于某种原因,将可见性设置为消失与DrawerLayout的逻辑冲突,即视图是否显示,因此它试图隐藏它。

从XML中去掉这一点会使所有内容看起来都一样(因为DrawerLayout会查看layout_gravity来决定哪些子视图是抽屉并隐藏它们本身),而不会出现奇怪的跳跃。

相关内容

最新更新