2014-12-22 144 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,则调整此视图的填充以为系统窗口留出空间。