How to show / hide FAB on scroll Recycle view with parent coordinator

I have an activity with the activity of the layout.inside coordinator, there is a fragment with a Recycler view and a float button. How can I show / hide the float button while viewing a Scroll Recycler and avoid using the fab behavior ?!

in the action layout: Layout Coordinator -----> AppBarLayout ----> Toolbar and FrameLayout view and bottom bar

in the fragment layout: RelativeLayout ----> View button and recycler float

I want to implement something like the Google+ homepage. how can i implement this scenario?


Temporary I used this solution for my problem:

using the activity layout coordinator by interface in my snippet and show / hide fab with fab behavior ... until I find the best solution !!!

+6
source share
2 answers

Edited

This code works very well:

mRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if(dy > 0){ mFab.hide(); } else{ mFab.show(); } super.onScrolled(recyclerView, dx, dy); } }); 

I tested and worked on my smartphone. Happy coding!

You can not:

 app:layout_anchor="@id/listView" app:layout_anchorGravity="bottom|end" 

Take a look here :

CoordinatorLayout support for ListView support according to this Google post .

+12
source

I modified the Leonondro method so that the FAB will hide when scrolling and show when scrolling stops.

 scrollListener = new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { switch (newState) { case RecyclerView.SCROLL_STATE_IDLE: fab.show(); break; default: fab.hide(); break; } super.onScrollStateChanged(recyclerView, newState); } }; rv.clearOnScrollListeners(); rv.addOnScrollListener(scrollListener); 
+2
source

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


All Articles