DrawerLayout with two drawers: the right "jump" when it opens?

My application has a DrawerLayout with two drawers in it, one on the left for navigation and one on the right for notifications. When the application goes through a cold start and I open the left drawer, the right drawer jumps from the left edge of the screen to the right.

It looks like this: http://i.imgur.com/mhoJ7MZ.gifv

As shown in the video, I tried to use the DrawerLayout isDrawerOpen and isDrawerVisible methods to try to figure out if he really believes that the right box is open when it is not (because it seems to β€œclose” the box when the left is open), but I don’t received from this.

What causes a weird jump?

My XML activity is below, full code is here .

 <?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> 
+5
source share
1 answer

The problem arises from the android:visibility="gone" LinearLayout in LinearLayout . For some reason, there is visibility that is in conflict with the DrawerLayout logic if the view is displayed or not, so it tries to hide it.

Taking this from XML makes everything look the same (since DrawerLayout looks at layout_gravity to decide which child views are boxes and hides them themselves) and doesn't have a weird transition.

+8
source

Source: https://habr.com/ru/post/1212735/


All Articles