Add image to CollapsingToolbarLayout

0

I would like to add a background image to a CollapsingToolbarLayout as in this example:

Itriedthefollowing:

<android.support.design.widget.AppBarLayoutandroid:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:background="@drawable/blue_sky"
                app:layout_collapseMode="parallax"/>





            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

But it shows feathers the background color!

How can I add the image?

    
asked by anonymous 24.04.2016 / 02:51

1 answer

1

Use this:

<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_CollapsingToolbarLayout"
    android:id="@+id/appBar"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="@color/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

       <ImageView
            android:id="@+id/ivPerfilCl"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/logo"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"

            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/tbDetalhes"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin"
            app:theme="@style/toobar"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_height="?attr/actionBarSize"
            android:minHeight="?attr/actionBarSize"
            />

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

</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/nested"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    app:borderWidth="0dp"
    android:src="@drawable/ic_event_available_white_24dp"
    app:layout_anchor="@id/appBar"
    app:layout_anchorGravity="bottom|right|end"
    android:elevation="2dp"
    android:layout_marginRight="16dp"
    android:id="@+id/FABParticiparDaAtividade"
    app:fabSize="normal"
    />
</android.support.design.widget.CoordinatorLayout>

In my works. Look how it was.

    
24.04.2016 / 03:10