Android smoothes toolbar hiding when scrolling

I use the toolbar inside ListFragment in Android and can hide / show it while scrolling. I implement AbsListView.OnScrollListener and use this code inside:

 @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // Leave this empty } /** * Method to detect if the scroll status changed * * @param listView * @param scrollState */ @Override public void onScrollStateChanged(AbsListView listView, int scrollState) { if (!isTablet) { final int currentFirstVisibleItem = listView.getFirstVisiblePosition(); if (currentFirstVisibleItem > mLastFirstVisibleItem) { ((ActionBarActivity) getActivity()).getSupportActionBar().hide(); } else if (currentFirstVisibleItem < mLastFirstVisibleItem) { ((ActionBarActivity) getActivity()).getSupportActionBar().show(); } mLastFirstVisibleItem = currentFirstVisibleItem; } } 

So the toolbar is hidden when I scroll down and show if I scroll up. But the animation is very "difficult", and I would like to have a smoother transition. It should look like this (without tabs, just a toolbar): https://cms-images.idgesg.net/images/article/2014/10/playscroll-100509755-large.gif

+6
source share
1 answer

I solved the problem using this library: https://github.com/ksoichiro/Android-ObservableScrollView

I changed the ToolbarControlListView example and now I have smooth animation. Therefore, I also had to modify the layout file of my ListView, which did not consist of FrameLayout as a parent. Take a look at the examples on GitHub!

+7
source

Source: https://habr.com/ru/post/979838/


All Articles