Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 385
ravindu1024 Avatar asked Aug 17 '16 07:08

ravindu1024


1 Answers

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

like image 158
Rupinder Kaur Avatar answered Oct 16 '22 22:10

Rupinder Kaur