Tried with CoordinatorLayout as in this tutorial but did not work. I think this is due to the fact that my ListView is inside SwipyRefreshLayout

Googled, but everywhere it says only RecyclerView or ListView without a wrapper.

Question: How can I still hide / show FAB if the ListView is wrapped?

    2 answers 2

    I achieved this by adding a listener to the lv. Here is an example:

     listView.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_IDLE){ fab.animate().scaleX(1f).scalY(1f).start(); flag = true; } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (flag){ fab.animate().scaleX(0f).scalY(0f).start(); flag = false; } } }); 

    That's the way an excellent library to facilitate the work with takhiventami.

    • I got the error java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewPropertyAnimator android.support.design.widget.FloatingActionButton.animate()' on a null object reference - DevOma
    • So you are trying to animate a button that does not exist yet. I advise you to do debugging. - Arnis Shaykh
    • Added changes to make animation work correctly. - Arnis Shaykh
    • Unfortunately, Disappears, does not appear back - DevOma
    • Added appearance animation. - Arnis Shaykh

    For ListView, apparently, there are no values ​​of the scrolled pixels. Save the solution below only for RecyclerView.

     mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (dy > 0 || dy < 0 && mSearchFAB.isShown()) { mSearchFAB.hide(); } } @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { mSearchFAB.show(); } super.onScrollStateChanged(recyclerView, newState); } }); 
    • C ListView also possible. See my answer. - Arnis Shaykh
    • @ArnisShaykh, I know that it is possible) It’s just impossible to do it there starting from changes along the axes. Only from the state. And it’s not very clear why you are animating FAB in a non-standard way in response - YuriySPb ♦
    • Because I do not use the Google Fab, but I make my own custom ones. Out of habit, he wrote) besides more universally) - Arnis Shaykh