2016-05-01 138 views
1

我目前正试图用协调布局,以塌陷的图像 - 在透明状态栏中的主题 - ,但在三个问题都困扰着我:协调布局和透明状态栏

  1. 当活动是开始时,图像没有显示在状态栏的后面(如果我删除了协调器布局,它可以工作);
  2. 当我向上滚动时,我想将状态栏更改为纯色,但图像的一部分仍然显示;
  3. 添加AppBarLayout和CollapsingToolbarLayout后,图像的底部 - 与状态栏的高度相同 - 剪切;

image below status bar - even though it is set to be transparent in the theme 图像仍低于状态栏 - 即使它被设置为透明的主题倒塌后

Status bar after collapsing - it should have a solid color 状态栏 - 它应该有一个纯色

代码:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorPrimary" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true" 
      app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 
      app:statusBarScrim="@color/colorPrimary" 
      app:contentScrim="@color/colorPrimaryDark"> 

      <RelativeLayout 
       android:id="@+id/cover_wrapper" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/rsc_character_details_cover_height"> 

       <ImageView 
        android:id="@+id/cover" 
        android:layout_width="match_parent"     android:layout_height="@dimen/rsc_character_details_cover_height"/> 
      </RelativeLayout> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/cover_wrapper" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:weightSum="6"> 

      ... 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 
</android.support.design.widget.CoordinatorLayout> 

这是我如何设置状态栏透明度:

<item name="android:windowTranslucentStatus">true</item> 

任何帮助将是非常赞赏。 非常感谢。

+1

这是因为'CollapsingToolbarLayout'是为了“工具栏”的包装。 – tachyonflux

回答

2

对于图像没有显示在状态栏后面并被切断的问题,应该在状态栏区域显示的任何内容应该有android:fitsSystemWindows="true"。即。您的cover_wrappercover

+0

就是这样!非常感谢 –

+0

是不是相反?来自docs:android:fitsSystemWindows 布尔内部属性可根据系统窗口(如状态栏)调整视图布局。如果为true,则调整此视图的填充以为系统窗口留出空间。 – GPack

+0

@GPack一些设计库组件修改标志的行为https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec – tachyonflux