0

I have an appBarLayout with a collapsingToolbar. I want to add a linearLayout below collapsingToolbar that will scroll with the appBarLayout. I have added app:layout_scrollFlags="scroll" but doesn't seem to work. Am I missing something or it is just not possible?

heres the code:

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_layout"
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.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/white"
            android:orientation="vertical"
            app:layout_collapseMode="none"
            app:layout_collapseParallaxMultiplier="0.3">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:scaleType="centerCrop"/>
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>
    </android.support.design.widget.CollapsingToolbarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll">
        ...
    </LinearLayout>
</android.support.design.widget.AppBarLayout>

here's the image

1 Answers1

0

Hi Michael your on the right path just a little change, copy paste this code in studio and try.

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_layout"
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.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/white"
            android:orientation="vertical"
            app:layout_collapseMode="none"
            app:layout_collapseParallaxMultiplier="0.3">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:scaleType="centerCrop"/>
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?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"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="@dimen/activity_horizontal_margin" >
                <!-- Your content here -->
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

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

Here's an example, http://www.androidauthority.com/using-coordinatorlayout-android-apps-703720/ Hopefully it helps you.

Rishabh Bhatia
  • 1,019
  • 6
  • 14
  • thanks but what i want to do is to put the linearlayout inside the appbarlayout because i will eventually add a tablayout below that linearlayout. i want the linearlayout to be scrolled with the appbar and the tablayout should be pinned while doing the scroll. then i will add the nestedscrollview with other contents – Michael Allen De Jesus May 11 '17 at 16:48
  • Is this gist what your trying to achieve Michael https://gist.github.com/iPaulPro/1468510f046cb10c51ea – Rishabh Bhatia May 11 '17 at 16:52
  • kinda. https://i.stack.imgur.com/L2Zih.png i want to do something like this. i will add a tablayout below that linearlayout – Michael Allen De Jesus May 11 '17 at 16:57
  • Cool do answers on http://stackoverflow.com/questions/33949530/how-insert-a-linearlayout-between-appbarlayout-and-the-scrolling-content-when-u & http://stackoverflow.com/questions/33660591/putting-content-below-appbarlayout-in-a-coordinatorlayout threads help you? – Rishabh Bhatia May 11 '17 at 17:04