Skip to content

Instantly share code, notes, and snippets.

@vogella
Created March 2, 2017 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vogella/51ce24171a34c2f6f68eaad570358fff to your computer and use it in GitHub Desktop.
Save vogella/51ce24171a34c2f6f68eaad570358fff to your computer and use it in GitHub Desktop.
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
final View tb = getActivity().findViewById(R.id.toolbar);
tb.animate()
.translationY(0)
.setInterpolator(new LinearInterpolator())
.setDuration(180)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
tb.setVisibility(View.VISIBLE);
}
});
} else if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
final View tb = getActivity().findViewById(R.id.toolbar);
tb.animate()
.translationY(tb.getHeight())
.setInterpolator(new LinearInterpolator())
.setDuration(180)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
tb.setVisibility(View.GONE);
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment