Reputation: 340
I have linear layout at the bottom and I want to hide that view on scroll up and show on scroll down. I was able to achieve that with scroll listener on recycler view . But there is one problem, when you are scrolling slow view is flickering (showing and hiding fast).
This is my code
bottom = (LinearLayout) getActivity().findViewById(R.id.linerabottom);
recycleList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
bottom.setVisibility(View.GONE);
} else {
bottom.setVisibility(View.VISIBLE);
}
}
});
Here is a video of the issue https://goo.gl/photos/TwUJjmPUA4kJCsaR8 .
Can you help me to find out what is the issue ? Thank you.
Upvotes: 1
Views: 2125
Reputation: 50588
This is normal, because your dy
at some point of time fluctuates between dy >= 0
and dy < 0
. If you want to achieve sort of quick return view, you should bound it to something like this:
recycleList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
mTotalDy += dy;
if (dy > 0 && mTotalDy >= bottom.getHeight()) {
bottom.setVisibility(View.GONE);
} else if(recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE && bottom.getVisiblity() == View.GONE) {
bottom.setVisibility(View.VISIBLE);
mTotalDy = 0;
}
}
});
Upvotes: 1