android - 将 windowTranslucentStatus 与 CollapsingToolbarLayout 一起使用

标签 android android-actionbar statusbar android-collapsingtoolbarlayout android-coordinatorlayout

我正在尝试获得与在 google play 上看到的效果类似的效果。

我有下面的布局来显示一个透明的工具栏,后面有一个图像。当用户滚动时, ImageView 会在它滚出屏幕时产生视差效果。当用户向上滚动时,工具栏就会返回,而 ImageView 仅在用户到达列表的顶部时才会返回。

这一切都很好。

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main"
    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.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="@color/background_material_dark">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:statusBarScrim="#09b"
            app:contentScrim="#09f">
            <ImageView
                android:id="@+id/img"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/location_banner"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7"
                />
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"
                android:fitsSystemWindows="true"
                app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

问题

当我将 windowTranslucentStatus 设置为 true 时。 View 中的内容上移到状态栏下方,但 CollapsingToolbarLayout 的内容上移两倍的状态栏高度(CollapsingToolbarLayout 保持正确的高度)。

这意味着图像顶部的某些部分被截断,操作栏现在显示在状态栏下方而不是下方。作为一个副作用,现在 CollapsingToolbarLayout 底部的填充与状态栏的高度相同

这就是没有 windowTranslucentStatus 的样子。这里一切正常 enter image description here

windowTranslucentStatus 设置为 true enter image description here

用户从列表下方(而不是顶部)向上滚动 enter image description here

最佳答案

设计库现已更新。我猜上面发布的问题是一个错误。

如果您将设计库更新到最新版本,则不再出现此问题。

我现在已经删除了所有 fitSystemWindows="true"除了 ImageView(因为它需要显示在状态栏下)。

我还从工具栏中删除了减号填充。

这是我 21 岁以上的主题

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:textColorPrimary">@android:color/white</item>
</style>

现在一切正常

关于android - 将 windowTranslucentStatus 与 CollapsingToolbarLayout 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30882429/

相关文章:

Android google directions api忽略街边

android - 如何在仅在特定 fragment 上可见的 ViewPage 操作栏上添加导航列表?

java - 单击操作栏中的共享应用程序链接时出现问题

ios - 动画状态栏 iOS 7

ios - 状态栏和导航栏的颜色不同,但实际上它们应该是相同的

android - 按下后退按钮时亮度不会保存

android - 使用 FFmpeg C API 调整视频大小

java - 无法在索引 1 处绑定(bind)参数,因为索引超出范围。该语句有 0 个参数

android - 如何更改android中操作栏标题的字体

excel - 使用VBA停止求解器更新状态栏