Kristofer
Kristofer

Reputation: 87

Why doesnt my Toolbar Collapse?

I'm trying to make a toolbar with a scroll view, so when the user scrolls down the toolbar collapses. There's no use for the toolbar other than having textviews. I've tried watching a bunch of videos on it but can't seem to find a solution. Also this is a fragment and not an Activity if that makes a difference.

My xml

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
tools:context=".MainActivity.MainActivity"
>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/CollapsingToolbarList"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        app:layout_scrollFlags="exitUntilCollapsed"
        app:contentScrim="@color/colorPrimary"
        app:expandedTitleTextAppearance="@color/colorTransparent"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbarList"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:title="@string/Shopping_List"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    </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:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/LinearLayoutShoppingList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/addItemsButton"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorLightBlack1"
            android:text="Add Items"
            android:textColor="@color/colorWhite"
            android:textSize="12sp"
            android:textAllCaps="false"/>

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/Dairy_RelativeLayout"
        android:layout_marginTop="30dp"
        android:layout_below="@id/LinearLayoutShoppingList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view1"
            android:layout_margin="10dp"
            android:layout_below="@id/Dairy_TextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:background="@drawable/shadow"
            android:layout_below="@id/Dairy_TextView"/>

        <TextView
            android:id="@+id/Dairy_TextView"
            android:layout_marginStart="20dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Dairy"
            android:textSize="20sp"
            android:textColor="@color/colorBlack"/>

    </RelativeLayout>
    </RelativeLayout>

</android.support.v4.widget.NestedScrollView>

Any help would be appreciated, Thank you!

Upvotes: 0

Views: 32

Answers (2)

Ammar Yasser
Ammar Yasser

Reputation: 148

As answered by Kristofer you should change

app:layout_scrollFlags="exitUntilCollapsed"

to

app:layout_scrollFlags="scroll|exitUntilCollapsed"

and also you do not need to use

app:layout_behavior="@string/appbar_scrolling_view_behavior"

when using NestedScrollingView

Upvotes: 0

Kristofer
Kristofer

Reputation: 87

I figured it out! You just have to change app:layout_scrollFlags="exitUntilCollapsed" to app:layout_scrollFlags="scroll|exitUntilCollapsed"

Upvotes: 1

Related Questions