【问题标题】:ImageView in CollapsingToolbarLayout not covering full height?CollapsingToolbarLayout 中的 ImageView 没有覆盖整个高度?
【发布时间】:2015-06-09 13:18:03
【问题描述】:

我在尝试实施新的CollapsingToolbarLayout 时遇到了一些问题。滚动、展开和折叠确实可以正常工作,但我的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>

在我看来,与奶酪 Chris Banes 应用程序的唯一区别是我将 app:layout_behavior 提供给 FrameLayout。但是,在该框架内,我加载了具有 NestedScrollView 作为根视图的片段,这似乎工作正常。

【问题讨论】:

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


    【解决方案1】:

    我遇到了同样的问题,折叠工具栏没有覆盖图像的整个高度,但是通过从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"
    

    就是这样,很好......

    【讨论】:

      【解决方案2】:

      我发现蓝色条带是工具栏背景。也就是说,我有:

      <item name="toolbarStyle">@style/MyToolbarStyle</item>
      

      在我的主题中,并且:

      <style name="MyToolbarStyle">
          <item name="android:background">?attr/colorPrimary</item>
      </style>
      

      我曾经有这个用colorPrimary 为工具栏着色。但是,如果您想迁移到设计库,您应该摆脱它:折叠的工具栏颜色已经由CollapsingToolbarLayout 上的app:contentScrim 属性管理。

      【讨论】:

      • 我有完全相同的问题,我的图像视图始终位于工具栏下方。我不确定我是否理解你是如何解决这个问题的。
      • 我删除了所有工具栏的 android:background 属性,包括样式和布局文件。
      猜你喜欢
      • 2011-02-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      相关资源
      最近更新 更多