I am trying to learn about CollapsingToolbarLayout which has some value set to scrollFlags
to control how the view within it will collapse. Can anybody clearly demarcate the difference between these flags:
How do these work when we set these flags to both Toolbar and CollapsingToolbarLayout.
And so, I will discuss app:layout_scrollFlags attribute from AppBarLayout.LayoutParams. This attribute is responsible for a scrolling behavior of AppBarLayout and its children. You can apply it directly to AppBarLayout or on the inside views, in the xml layout of your AppCompatActivity.
exitUntilCollapsed. Scroll Up: the view is always visible, provided its height is > 0 and the expanded version (e.g. Toolbar with an ImageView) will become visible when scrolled all the way up.
CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout .
I've made a table to clear things up. Also wrote quite an informative blog post with an example code on GitHub :)
Scroll Up: the view becomes visible when the layout's been scrolled all the way up Scroll Down: the view scrolls with the rest of the content like it's a part of it; will hide if the layout's height is bigger than the screen's one
Scroll Up: the view becomes visible on every scroll up action, even if there's still a lot of content to scroll up Scroll Down: the view scrolls with the rest of the content like it's a part of it; will hide if the layout's height is bigger than the screen's one
Scroll Up: the collapsed version of the view (e.g. Toolbar
) becomes visible on every scroll up action, and it expands (e.g. Toolbar
with an ImageView
) only when scrolled all the way up
Scroll Down: the view collapses and then hides, if the layout's height is bigger than the screen's one
Scroll Up: the view is always visible, provided its height is > 0 and the expanded version (e.g. Toolbar with an ImageView) will become visible when scrolled all the way up
Scroll Down: the view scrolls with the rest of the layout's content, but only till its collapsed state (hence - "exit until collapsed"), so in case of a Toolbar
with a fixed height, it will always be visible on the top
Scroll Up AND Down fast scrolls up or down based on how much of the view is visible - if more than 50% - the view will scroll down, showing itself, if less - the view will hide; used with other flags as a further customization
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With