Skip to content

Instantly share code, notes, and snippets.

@VladimirMi
Last active March 1, 2018 11:40
Show Gist options
  • Save VladimirMi/6ea62215cd0c04f8aa2476e28b3cc7da to your computer and use it in GitHub Desktop.
Save VladimirMi/6ea62215cd0c04f8aa2476e28b3cc7da to your computer and use it in GitHub Desktop.
Turn on/off scrolling of collapsing toolbar
private void setupScrolling() {
NestedScrollView scroll = findViewById(R.id.movie_details_scroll);
CollapsingToolbarLayout collapsing = findViewById(R.id.toolbar_layout);
boolean canScroll = Utils.canScroll(scroll);
int scrollFlags = 0;
if (canScroll) {
scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL |
AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED;
}
AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) collapsing.getLayoutParams();
lp.setScrollFlags(scrollFlags);
collapsing.setLayoutParams(lp);
}
public static boolean canScroll(NestedScrollView scrollView) {
View child = scrollView.getChildAt(0);
if (child != null) {
int childHeight = child.getHeight();
return scrollView.getHeight() < childHeight + scrollView.getPaddingTop() + scrollView.getPaddingBottom();
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment