CollapsingToolbarLayout 内的 ImageView 在某些设备上不可见

ImageView inside CollapsingToolbarLayout not visible in certain devices

我正在使用 CollapsingToolbarLayout,里面有两张图片,一张作为背景,一张作为上部徽标。这个想法是使它们都具有视差。这个东西在 Android 5 的物理设备上工作正常,但在低版本的设备(或模拟器)上就不行了。有点奇怪。

这是我的布局:

<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">

    <NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >

        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="#fff">

            <!--content--> 
        </FrameLayout>

    </NestedScrollView>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:background="#222">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll">
            <ImageView
                android:id="@+id/header_bk"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/background"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7"
                />
            <ImageView
                android:id="@+id/header_logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/ic_logo"
                app:layout_collapseMode="parallax"
                android:background="#44ff0000"
                />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

我找到了让它工作的方法。在 <5 Android 版本中,CollapsingToolbarLayout 中带有 wrap_content 的视图似乎有问题。更改为 match_parent 并使用 scale_type="center" 使图像保持居中确实解决了我的问题。

图像布局的变化如下:

<ImageView
    android:id="@+id/header_logo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="center"
    android:layout_gravity="center"
    android:src="@drawable/ic_adi_logo"
    app:layout_collapseMode="parallax"
    />