2015-02-05 18 views
5

我的應用程序有一個DrawerLayout,裏面有兩個抽屜,一個在左側用於導航,另一個在右側用於通知。當應用程序經歷冷啓動並且左側抽屜滑動打開時,右側抽屜從屏幕的最左側跳到右側。帶兩個抽屜的DrawerLayout:右邊一個打開時是「跳躍」?

它看起來像這樣:http://i.imgur.com/mhoJ7MZ.gifv

如視頻所示,我已經使用DrawerLayoutisDrawerOpenisDrawerVisible方法試試,看它是否真正認爲正確的抽屜被打開時,它沒有試過(因爲當左邊的一個被打開時,它似乎「關閉」抽屜),但是我沒有從中得到任何有用的東西。

什麼導致了怪異的跳躍?

我的活動的XML如下,完整的代碼是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> 

回答

8

問題來自於LinearLayout S上android:visibility="gone"元素 - 對於某些有理由可見性設置爲與DrawerLayout的邏輯,如果該視圖顯示或不走了衝突,所以它會試圖將其隱藏。

從XML中取出所有內容看起來都一樣(因爲DrawerLayout查看layout_gravity以確定哪些子視圖是抽屜並將它們隱藏起來)並且沒有奇怪的跳轉。

+0

測試:這個答案是一流的。 – 2017-05-05 20:27:20

相關問題