2014-12-22 143 views
0

透明狀態欄我使用的方式https://stackoverflow.com/a/27051852/3875363實現狀態欄後面的抽屜展示片段,它似乎很動聽前只停留了一個視圖。上隱藏後底部奇怪填充和使用DrawerLayout

但我面臨着一個奇怪的情況後,我隱藏和顯示這個片段,一個白色填充出現在drawerlayout的底部,它喜歡在下面。

enter image description here

我的評論最代碼顯示一個簡單的例子。

活動的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/content_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

</FrameLayout> 

片段與抽屜

<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" 
             xmlns:android="http://schemas.android.com/apk/res/android" 
             xmlns:tools="http://schemas.android.com/tools" 
             android:layout_width="match_parent" 
             android:layout_height="match_parent" 
             android:fitsSystemWindows="true" 
             tools:context=".MainActivity"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <include 
      android:id="@+id/action_bar_in_list" 
      layout = "@layout/toolbar"/> 

    </RelativeLayout> 

    <com.ghostflying.portalwaitinglist.ScrimInsetsFrameLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/debug_content" 
     android:background="@color/setting_item_group_title_text" 
     app:insetForeground="#4000" 
     android:fitsSystemWindows="true" 
     android:layout_gravity="start" 
     android:layout_height="match_parent" 
     android:layout_width="@dimen/navigation_drawer_width"> 

    </com.ghostflying.portalwaitinglist.ScrimInsetsFrameLayout> 
</android.support.v4.widget.DrawerLayout> 

所述第二片段的佈局的佈局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

    <!-- TODO: Update blank fragment layout --> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/hello_blank_fragment"/> 

</FrameLayout> 

一旦我隱藏抽屜片段顯示第二個片段,然後彈出返回堆棧返回。抽屜碎片看起來像圖像,總是出現狀態欄高度的填充。這麼奇怪。

回答

0

嘗試從DrawerLayout刪除android:paddingBottomandroid:paddingTop使抽屜不包括狀態欄,但沒有理由在底部複製填充。

編輯: 您的更新後,我分析這一次,我覺得你的問題可以通過你的不尋常的設計造成的。所有指南都建議DrawerLayout應該是根元素的視圖層次結構(如您在您提供的示例中)。在這裏看到:link

所以我建議這些解決方案之一。

  1. 使用單獨活動有和沒有抽屜顯示視圖。 (我推薦這個,特別是當你的抽屜起到導航的作用。)

  2. 使用一個活動與抽屜佈局根和放片段作爲出票人的主要內容。如果你不想抽屜能打開使用改變後的片段這種方法: mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

+0

事實上,填充是全0dp,我評論大部分代碼,看起來也很奇怪,我稍後會編輯這個問題。 – GhostFlying

0

嘗試刪除了android屬性:

fitsSystemWindows = "true" 

這爲我工作。

根據官方文檔這是一個

布爾內部屬性基於系統狀態欄, 窗口調整視圖佈局。如果爲true,則調整此視圖的填充以爲系統窗口留出空間。