CollapsingToolbarLayout背景图片不起作用

时间:2016-10-05 10:54:52

标签: android image android-collapsingtoolbarlayout

在我的Android应用中,CollapsingToolbarLayout的背景图片在使用Android 4.4.2的设备中显示正常,但在5.1中则没有。它只显示colorPrimary。我尝试在ImageView中使用src属性,但结果相同。

''”

review_id

'''

1 个答案:

答案 0 :(得分:3)

这应该是

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".classes.MainActivity"
    tools:ignore="RtlHardcoded">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorToolbar"
            app:expandedTitleGravity="center"
            app:expandedTitleMarginBottom="64dp"
            app:expandedTitleTextAppearance="@style/CollapsingTextAppearance.Inverse"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="@string/flexible_title">

            <ImageView
                android:id="@+id/bgImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:contentDescription="@null"
                android:minHeight="100dp"
                android:scaleType="centerCrop"
                android:src="@drawable/bg"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/flexible.example.toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@null"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

</android.support.design.widget.CoordinatorLayout>