Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between different scrollFlags for CollapsingToolbarLayout

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:

  • scroll
  • enterAlways
  • exitsUntilCollapsed
  • enterAlwaysCollapsed
  • enterAlways

How do these work when we set these flags to both Toolbar and CollapsingToolbarLayout.

like image 980
user2779311 Avatar asked May 13 '16 16:05

user2779311


People also ask

What is layout_scrollFlags?

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.

What is exitUntilCollapsed?

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.

What is CollapsingToolbarLayout?

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 .


1 Answers

I've made a table to clear things up. Also wrote quite an informative blog post with an example code on GitHub :)

scroll

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

enterAlways

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

enterAlwaysCollapsed

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

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 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

snap

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

like image 200
lomza Avatar answered Sep 24 '22 23:09

lomza