【问题标题】:Coordinator layout and transparent status bar协调器布局和透明状态栏
【发布时间】:2016-05-01 08:57:44
【问题描述】:

我目前正在尝试使用协调器布局来折叠图像 - 在具有透明状态栏的主题中 - 但是三个问题困扰着我:

  1. Activity 启动时,状态栏后面没有显示图像(如果我删除 coordinatorlayout,它可以工作);
  2. 当我向上滚动时,我想将状态栏更改为纯色,但仍有一部分图像显示;
  3. 添加 AppBarLayout 和 CollapsingToolbarLayout 后,图像底部 - 与状态栏高度相同 - 被剪切;

图像仍保留在状态栏下方 - 即使在主题中设置为透明

折叠后的状态栏 - 它应该是纯色

代码:

<?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>

任何帮助将不胜感激。 非常感谢。

【问题讨论】:

  • 这是因为CollapsingToolbarLayoutToolbar 的包装器。

标签: android android-layout android-design-library


【解决方案1】:

对于图片不显示在状态栏后面和被截断的问题,任何应该显示在状态栏区域的东西都应该有android:fitsSystemWindows="true"。 IE。你的cover_wrappercover

【讨论】:

  • 就是这样!非常感谢
  • 不是相反吗?来自文档:android:fitsSystemWindows 布尔内部属性,用于根据状态栏等系统窗口调整视图布局。如果为 true,则调整此视图的填充以为系统窗口留出空间。
  • @GPack 一些设计库组件修改标志medium.com/google-developers/…的行为
  • @karaokyo 通过阅读链接的已知帖子,我了解到仅修改了第一个深度行为,而不是 true 的含义(为系统装饰保留空间的填充)和false (不是填充:视图将位于系统装饰的后面)。我错了吗?
  • @GPack 问题是我不知道你想从我这里得到什么。你引用了一些文档,在实践中它以某种方式工作,你可以自己看到。
猜你喜欢
  • 1970-01-01
  • 2014-08-19
  • 1970-01-01
  • 1970-01-01
  • 2017-01-18
  • 1970-01-01
  • 2015-07-06
  • 2017-05-28
  • 1970-01-01
相关资源
最近更新 更多