android - CollapsingToolbarLayout 中的 ImageView 未覆盖全高?

标签 android android-layout android-design-library androiddesignsupport

我在尝试实现新的 CollapsingToolbarLayout 时遇到了一些问题。滚动、展开和折叠都可以正常工作,但我的 ImageView(无论我设置什么类型的资源)都没有覆盖展开工具栏的整个高度。看这里:

expanded collapsed

这里我在 ImageView 上设置了 android:src="@color/red" ,但它从未覆盖真正的工具栏。它也不适用于位图。我在下面发布我的布局。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- content -->
    <android.support.design.widget.CoordinatorLayout
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.design.widget.AppBarLayout
            android:layout_height="@dimen/appbar_expanded_height"
            android:layout_width="match_parent"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:fitsSystemWindows="true">
            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp"
                app:contentScrim="?attr/colorPrimary"
                android:fitsSystemWindows="true">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:src="@color/red_600"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax"
                    />
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    app:layout_collapseMode="pin"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize">
                </android.support.v7.widget.Toolbar>

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

        <!-- I load fragments here -->
        <FrameLayout
            android:id="@+id/fragment_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </android.support.design.widget.CoordinatorLayout>

    <!-- nav drawer -->
    <fragment
        android:layout_width="@dimen/drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>

在我看来,与 cheese-Chris Banes-app 的唯一区别是我将 app:layout_behavior 赋予 FrameLayout。但是,在该框架内,我加载了具有 NestedScrollView 作为 Root View 的 fragment ,这似乎工作正常。

最佳答案

我有同样的问题,折叠的工具栏没有覆盖图像的整个高度,但是通过从 AppBarLayout 中删除单行来修复。也就是说,您只需要删除 android:fitsSystemWindows="true 就可以了。

<android.support.design.widget.AppBarLayout
        android:layout_height="@dimen/appbar_expanded_height"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

去掉最后一行,即as。

 android:fitsSystemWindows="true"

就是这样,一切顺利......

关于android - CollapsingToolbarLayout 中的 ImageView 未覆盖全高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30733159/

相关文章:

android - 在 Mac OS X 上哪里安装 Android SDK?

java - 如何根据一列对一维(或二维)数组(多维)进行排序?

android - 看不到第二个按钮

android - 在 CoordinatorLayout 中平滑 ImageView 滚动

android - 如何更改 TextinputLayout 标签的颜色和 edittext 下划线 android

android - Intent 或直接访问不同类的公共(public)变量

android - 在哪里可以创建对 Windows 资源管理器和我的 Android 应用程序可见的目录?

android - 工具栏在 Intent/AppCompatActivity 中的菜单膨胀时给出 fatal error

android - TextView 不粘在右上角

android:如何使用 CoordinatorLayout 和半透明导航栏?