Glide + CollapsingToolbarLayout奇怪的行为

时间:2016-06-10 21:11:05

标签: android android-layout android-glide

使用CollapsingToolbarLayout,工具栏和嵌入的ImageView时,我遇到了一种奇怪的行为。 这是我的代码:

<android.support.design.widget.AppBarLayout
        android:id="@+id/bla"
        android:layout_width="match_parent"
        android:layout_height="256dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/md_white_1000"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
                app:theme="@style/ThemeOverlay.AppCompat.Light" />

            <ImageView
                android:id="@+id/fragment_kids_profile_pic"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop" />

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

Glide建设者:

Glide.with(getActivity())
                .load(file)
                .fitCenter()
                .into(profilePicture);

在通过Glide设置图像之前,工具栏行为完全正常,在我的情况下是“固定”。设置图像后,工具栏布局丢失,图像发生(向上滚动后)。 一些照片要澄清:

在设置图片之前: Before scrolling enter image description here enter image description here enter image description here

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:5)

这是因为CollapsingToolbarLayout扩展了FrameLayout。 在FrameLayout中,视图层次结构中的最后一个视图位于顶部(如果您还没有在代码中更改过),那么ImageView覆盖{Toolbar是正常的{1}}。要解决这个问题&#34;问题&#34;你只需改变顺序:

<android.support.design.widget.AppBarLayout
    android:id="@+id/bla"
    android:layout_height="256dp"
    android:layout_width="match_parent">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/fragment_kids_profile_pic"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:scaleType="centerCrop" />

        <android.support.v7.widget.Toolbar
            android:background="@color/md_white_1000"
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
            app:theme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

在通过Glide设置图片之前,ImageView的背景是透明的,这就是您可以看到Toolbar的原因。

相关问题