Created
September 18, 2017 10:01
-
-
Save rezaiyan/e611cddcd4aed64b8924382c4d54e7cd to your computer and use it in GitHub Desktop.
hide show view with scrolling recyclerview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.daimajia.slider.library; | |
import android.support.v7.widget.RecyclerView; | |
/** | |
* Created by Rezaiyan on 9/18/2017. | |
*/ | |
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { | |
private static final int HIDE_THRESHOLD = 20; | |
private int scrolledDistance = 0; | |
private boolean controlsVisible = true; | |
@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 onHide(); | |
public abstract void onShow(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ListScroller(){ | |
recyclerView.setOnScrollListener(new HidingScrollListener() { | |
@Override | |
public void onHide() { | |
hideSearchBar(); | |
} | |
@Override | |
public void onShow() { | |
showSearchBar(); | |
} | |
}); | |
} | |
private void hideViews() { | |
mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2)); | |
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFabButton.getLayoutParams(); | |
int fabBottomMargin = lp.bottomMargin; | |
mFabButton.animate().translationY(mFabButton.getHeight()+fabBottomMargin).setInterpolator(new AccelerateInterpolator(2)).start(); | |
} | |
private void showViews() { | |
mToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)); | |
mFabButton.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment