Aman Gupta February 2016

Toolbar leaving space when i tryed to hide on RecyclerView scroll

I am trying to hide my toolbar on the scroll of recyclerView. And it hides on the scroll but the problem is that it leaves blank space after hiding.

Here, I am attaching the screen shot of the toolbar.

enter image description here

After Hiding the toolbar

enter image description here

this is my xml file - category_activity.xml

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

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways" />

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


    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


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

toolbar.xml

&l        

Answers


Kalpesh Kikani February 2016

toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();

If you want to show it again you call:

toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();

http://rylexr.tinbytes.com/2015/04/27/how-to-hideshow-android-toolbar-when-scrolling-google-play-musics-behavior/


Aman Gupta February 2016

I have found the problem and fixed it. Actually, the problem is in include tag.

In above code, I had used include tag and include tag can't perform the functionality of the toolbar. Means

app:layout_scrollFlags="scroll|enterAlways"

does not work in include tag.

If I use the toolbar directly in the XML file with scrollFlags then everything works fine.

Or in toolbar.xml add the layout_scrollFlags

toolbar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:titleTextColor="#FFFFFF"
    app:layout_scrollFlags="scroll|enterAlways"   
    />

After changing it, I have not needed to hide and show the toolbar manually.

and Everything is working fine.

Post Status

Asked in February 2016
Viewed 3,750 times
Voted 5
Answered 2 times

Search




Leave an answer