android - Hiding Toolbar smoothly on RecyclerView Scroll? -


currently i've recyclerview holds list of items. i'm listening scroll listener of recyclerview , if recyclerview @ point 500, should hide toolbar , should remain hide when crosses 500+. similarly, shows toolbar when reaches <= 450.

this code i've tried far. problem is,

  1. it hides toolbar flashes when hides or shows @ mentioned point.
  2. how achieve smooth toolbar hide?

    recyclerview.addonscrolllistener(new recyclerview.onscrolllistener() {         @override         public void onscrollstatechanged(recyclerview recyclerview, int newstate) {             super.onscrollstatechanged(recyclerview, newstate);           }           @override         public void onscrolled(recyclerview recyclerview, int dx, int dy) {             super.onscrolled(recyclerview, dx, dy);              scrolld = scrolld + dy;             log.d("key", "dy .." + (dy + scrolld));              if (scrolld >= 500) {               // code hide             }              if (scrolld <= 450) {                // code show              }         }     }); 

use coordinatorlayout instead of linear/relative layout , add following attribute toolbar.

app:layout_scrollflags="scroll|enteralways"

coordinatorlayout handles visibility of toolbar hiding when user scrolls down , showing again when user scrolls up.

code:

<?xml version="1.0" encoding="utf-8"?>  <!-- $id$ -->  <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent">      <android.support.design.widget.appbarlayout         android:id="@+id/appbarlayout"         android:layout_width="match_parent"         android:layout_height="wrap_content">       <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/tool_bar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         app:layout_scrollflags="scroll|enteralways"  />      </android.support.design.widget.appbarlayout>  </android.support.design.widget.coordinatorlayout> 

refer link : https://mzgreen.github.io/2015/06/23/how-to-hideshow-toolbar-when-list-is-scrolling(part3)/


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -