简体   繁体   中英

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.

From Antonio Leiva's blog here , the flags work like this:

scroll : This means it will scroll while scrolling the targeted view (our recycler view in this case).

enterAlways : When we scroll up, the view will immediately reappear.

enterAlwaysCollapsed : if the view has a collapsed mode, it will reappear collapsed when scrolling up.

exitUntilCollapsed : it won´t exit from the screen until the view is collapsed.

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 (eg Toolbar ) becomes visible on every scroll up action, and it expands (eg 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 (eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM