ravindu1024
ravindu1024

Reputation: 1534

How to place view above a CollapsingToolbarLayout

How can we place a static view above the CollapsingToolbarLayout inside an AppbarLayout? The organization inside my Coordinator view looks like this:

<AppBarLayout>
    <RelativeLayout/>             ----- should not collapse
    <CollapsingToolbarLayout/>    ----- should collapse
</AppBarLayout>
<NestedScrollView/>

The problem is that, when I add anything above the CollapsingToolbar they show up alright but breaks the collapsing functionality of the CollapsingToolbar.

The full xml:

<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="c.toolbar_test.ScrollingActivity2">

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button"/>
    </RelativeLayout>

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


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

<include layout="@layout/content_scrolling2"/>



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

So how can I have some content above the collapsing toolbar and still retain the collapsing functionality?

Upvotes: 9

Views: 1377

Answers (1)

Rupinder Kaur
Rupinder Kaur

Reputation: 91

Its too late but heres a solution What you can do is Take Parent Layout as Linear and Place its immidiate child your relative view and then add your coordinator layout as you want....

Upvotes: 5

Related Questions