Reputation: 2251
I have layout like that:
I would like to implement that functionality: When user ScrollDown RecyclerView
two things which he see are Toolbar
and FilterPanel
. The title
and image
is hidden, when he scroll up till to the beggining of the recyclerview
the title
and image
appear.
There is my HiddingScrollListener
:
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener {
private static final float HIDE_THRESHOLD = 10;
private int scrolledDistance = 0;
private boolean controlsVisible = true;
public HidingScrollListener() {
}
@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);
if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
onHide();
controlsVisible = false;
scrolledDistance = 0;
} else if (scrolledDistance < -HIDE_THRESHOLD && controlsVisible) {
onShow();
controlsVisible = true;
scrolledDistance = 0;
}
if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) {
scrolledDistance += dy;
}
}
public abstract void onShow();
public abstract void onHide();
}
And my implementation of this listener
in activity
:
mRecyclerView.addOnScrollListener(new HidingScrollListener() {
@Override
public void onShow() {
}
@Override
public void onHide() {
mTitle.setVisibility(View.GONE);
mImageView.setVisibility(View.GONE);
}
});
I don't know how to catch when RecyclerView
is in the beggining and how to show title
and image
in this case. And I have a problem: How to pin FilterPanel
under the Toolbar
when I scroll down?
Anyway, thank you!
Upvotes: 1
Views: 749
Reputation: 540
You should use the CoordinatorLayout
from the android design support library.
This layout coordinates between it's children events, most commonly scroll events. Here is a tutorial: https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout
Upvotes: 1