【问题标题】:When not collapsed some part of the the toolbar is visible over the ImageView of CollapsingToolbarLayout未折叠时,工具栏的某些部分在 CollapsingToolbarLayout 的 ImageView 上可见
【发布时间】:2016-09-03 01:40:55
【问题描述】:

CollapsingToolbarView 工作得很好,但是在折叠工具栏的 ImageView 上有这个不需要的条带。

如下所示,状态栏后面有一个红色条带(可能是工具栏)。我该如何摆脱它?

     

下面是相关的xml文件:

fragment_movie.xml

<android.support.design.widget.CoordinatorLayout
    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_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.jayeshsolanki.mmdb.ui.fragment.MovieFragment">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview_movie"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimaryDark"
            app:title="@string/placeholder_movie_item_title">

            <ImageView
                android:id="@+id/backdrop_movie"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:adjustViewBounds="true"
                app:layout_collapseMode="parallax"
                tools:src="@drawable/placeholder_movie_item_backdrop"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_movie"
                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.design.widget.CoordinatorLayout>

父活动的主题在Manifest中设置为"@style/AppTheme.NoActionBar"

【问题讨论】:

    标签: android xml android-layout android-coordinatorlayout android-collapsingtoolbarlayout


    【解决方案1】:

    android:fitsSystemWindows="true" 应该在CoordinatorLayoutAppBarLayoutCollapsingToolbarLayout 和其中的ImageView 上。

    【讨论】:

    • 谢谢,这解决了我的问题。从CoordinatorLayout 中删除android:fitsSystemWindows="true" 也有效,这看起来与在CoordinatorLayoutAppBarLayoutCollapsingToolbarLayoutImageView 中设置它相同。你能告诉我为什么我需要为所有这些视图使用它吗?
    • @jayeshsolanki93 坦率地说,直到今天我还没有为这个问题找到满意的答案。通常使用它是为了不将您的内容绘制在半透明状态和导航栏下方。 design 中的类支持库,但是结合 android:windowDrawsSystemBarBackgrounds(我认为)围绕此构建了一些特殊行为。
    • 提示:CollapsingToolbarLayout 在内部根据父 AppBarLayout 的值设置其 fitsSystemWindows。你不必在 XML 中设置它(虽然它没有坏处)
    【解决方案2】:

    尝试从图像中删除 adjustViewBounds 属性。您正在使用 centerCrop 应该足以让图像正确显示并填充所有空间。通过调整视图边界,您可以保留纵横比,因此图像不会填满应用栏空间。

    【讨论】:

    • 试过了,没用。
    • 尝试在应用栏布局后将回收站视图移到顶部?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 2019-01-28
    相关资源
    最近更新 更多