3

I'm building a collapsable toolbar and works well, but not how to make it stop when no more data to display. Always collapses in any case. For example: if there is no data to show in the recycler, the collapse of the toolbar should stop and prevent further collapsing

This is my code:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="224dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true"> 

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

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

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

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

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

    <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="3dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>
  • Did you figure out a solution to this problem? I ran into the same thing and the only thing that comes to mind so far not to have black space at the bottom of the recycleview lists. In theory that means dynamically setting the minHeight of the toolbar depending on the length of the items in the list below, but that feels very sketchy... – Leo K Feb 19 '16 at 22:22

1 Answers1

1

Its a known bug. Update your Support libraries to 22..2.1:

com.android.support:design:22.2.1

Else you can also do it programmatically :

try this

Community
  • 1
  • 1
Akshay
  • 6,029
  • 7
  • 40
  • 59
  • Hi, thanks for the answer, i update my Support library to 22.2.1 and only works when: 1.- min apk is 22; maybe 21 but (apk < android lollipop does not work) 2.- "Total.Height" = "Appbar.Height" + "WhiteSpace.Height" 2.1- if my "Recycler.Height" < "WhiteSpace.Height", not collapse, this is fine. 2.2 if my "Recycler.Height >"Total.Height", collapse until it min height this is fine 2.3 if my "Recycler.Height" < "Total.height" && "Recycler.Height" > "WhiteSpace.Height", collapse until it min height, but this is not fine. I need to stop when there is no more content to show in the Recycler – Renzo Oskar Aug 04 '15 at 21:44