CollapsingToolbarLayout expand only when at the top

后端 未结 5 870
耶瑟儿~
耶瑟儿~ 2021-02-05 17:58

I have some problems with AppBarLayout and CollapsingToolbarLayout. This is what currently happens:

https://www.youtube.com/watch?v=z4yD8rmjSjU

The downwards scr

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 18:15

    Customisation of CoordinatorLayout behaviour is hard. You want the orange bar to appear immediately but ImageView only after the content is scrolled to the top, but these views belong to one parent CollapsingToolbarLayout and both get either the behaviour you have now or the opposite with enterAlwaysCollapsed flag. I see no way to separate the behaviour for these views without messing with CoordinatorLayout/CollapsingToolbarLayout Java API.

    If simpler behaviour is not an option and noone here points out a simple solution, I suggest trying a relatively new MotionLayout instead of dancing with CollapsingToolbarLayout internals, you will save yourself a lot of time in the end. It will be a little harder at start but it provides clear ways for customisation. Here's a very good article that shows how to build a UX similar to CoordinatorLayout but using MotionLayout. And the second part of this article with some additional customisations.

提交回复
热议问题