CollapsingToolbarLayout中的ImageView在某些设备中不可见

jua*_*ile 7 android android-design-library android-coordinatorlayout android-collapsingtoolbarlayout

我正在使用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>
Run Code Online (Sandbox Code Playgroud)

jua*_*ile 9

我找到了一种让它发挥作用的方法.在<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"
    />
Run Code Online (Sandbox Code Playgroud)