CollapsingToolbarLayout在API 26中显示图像下的条形图

Dav*_*vid 8 android android-collapsingtoolbarlayout

将支持库从v25.4.0升级到v26.0.0后,CollapsingToolbarLayout它不适合内部的内容,但在下面显示一个空白区域(可能是状态栏的大小).为了显示:

使用v25.4.0:

随着v25.4.0

随着v26.0.0:

随着v26.0.0

那个XML布局Activity

<?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:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:src="@drawable/material_flat"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax" />

            <ImageView
                android:layout_width="86dp"
                android:layout_height="86dp"
                android:layout_gravity="bottom|start"
                android:paddingBottom="16dp"
                android:paddingLeft="16dp" />


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>

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


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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Minions ipsum ..." />

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我试过玩这个android:fitsSystemWindows值,正如这里所建议的,但结果不是预期的.如果你想查看更多细节,我的实现代码就是这个Github repo.

Ant*_*eef 5

我尝试编辑你的代码,我得到了你想要实现的想法结果:

在此处输入图片说明

我唯一编辑的是,我没有将 AppBarLayout 的 layout_height 设置为 ,而是将其wrap_content更改为190dp

在此处输入图片说明

我从这个 CheeseSquare 存储库中提出了这个解决方案:https : //github.com/chrisbanes/cheesesquare,这就是它如何使想法效果ImageView under transparent statusBar

在此处输入图片说明

如您所见,可以为AppBarLayout.

为什么在您的帖子中会出现蓝色条?

这个问题的答案来自两个因素: 1. 您将 AppBarLayout 的高度设置为wrap_content;2.你的imageViewfitsSystemWindows是真的。

当您将 fitsSystemWindows 设置为 true 时,imageView 将消耗窗口插入,并且视图本身上升到与 statusBar 完全相同的高度。当这种情况发生时,AppBarLayout 不会根据这个 imageView 滑动来调整它的高度,所以会出现一个丑陋的底部栏。

如何解决这个问题?

一种修复方法是尝试为您的 xml 文件中的 AppBarLayout 设置固定高度。这是简单的方法,就像我上面展示的那样。

如果您不知道图片的确切高度怎么办,就像您从互联网上下载这张图片一样?我的建议是,您也可以在您的活动中处理此问题。当图片背景下载完成后,您可以获得图像的测量高度,然后以编程方式获取 AppBarLayout 的高度。这也应该可以解决问题,不再留下任何障碍。