Created
February 28, 2015 08:10
-
-
Save mzgreen/95f93c615456c1d72104 to your computer and use it in GitHub Desktop.
HidingScrollListener class without snapping
This file contains hidden or 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
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { | |
private int mToolbarOffset = 0; | |
private int mToolbarHeight; | |
public HidingScrollListener(Context context) { | |
mToolbarHeight = Utils.getToolbarHeight(context); | |
} | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
clipToolbarOffset(); | |
onMoved(mToolbarOffset); | |
if((mToolbarOffset <mToolbarHeight && dy>0) || (mToolbarOffset >0 && dy<0)) { | |
mToolbarOffset += dy; | |
} | |
} | |
private void clipToolbarOffset() { | |
if(mToolbarOffset > mToolbarHeight) { | |
mToolbarOffset = mToolbarHeight; | |
} else if(mToolbarOffset < 0) { | |
mToolbarOffset = 0; | |
} | |
} | |
public abstract void onMoved(int distance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment