Last active
March 1, 2018 11:40
-
-
Save VladimirMi/6ea62215cd0c04f8aa2476e28b3cc7da to your computer and use it in GitHub Desktop.
Turn on/off scrolling of collapsing toolbar
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 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); | |
} |
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
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