I am using a Toolbar inside a ListFragment in Android and can hide/show it during 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;
}
}
This way the Toolbar is hidden when I scroll down and shown if I scroll upwards. But the animation is very "hard" and I would like to have a smoother transition. It should look like this (without tabs, just the Toolbar): https://cms-images.idgesg.net/images/article/2014/10/playscroll-100509755-large.gif
I solved the problem using this library: https://github.com/ksoichiro/Android-ObservableScrollView
I modified the ToolbarControlListView example and now I have a smooth animation. Therefore I also had to change the layout file of my ListView which didn't consist of a FrameLayout as parent. Take a look at the examples in GitHub!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With