CollapsingToolbar not working with not-so-tall content

后端 未结 1 1742
抹茶落季
抹茶落季 2020-12-13 19:20

I\'m pretty sure this is a bug, so I\'m asking for a workaround. My layout is like:



    
        

        
相关标签:
1条回答
  • 2020-12-13 20:03

    The trick is to add android:layout_gravity="fill_vertical" to the NestedScrollView. This way the toolbar collapses and expands smoothly & reacts to scroll gestures for any non-empty NestedScrollView, no matter its size.

    Of course if the scroll view is empty, the toolbar won't collapse by scrolling in the "content" part of the screen. But that doesn't seem so bad to me.

    Update

    Looks like this solution has some issues with larger contents, as the very bottom part of the content will remain hidden. I could find that the hidden part is (appears to be) as big as the collapsed toolbar height. That makes it easy to define a workaround - just add a margin to the bottom of the ScrollView, so that it gets measured and releases the bottom, hidden part. Thus:

    android:layout_gravity="fill_vertical"
    android:layout_marginBottom="?attr/actionBarSize"
    

    or whatever size you gave to the Toolbar in your view. Note that this solution fits well with small and large contents, but scrolling is not so smooth with smaller ones.

    Update2 (july 2015)

    From early tests, it looks that this bug has been fixed in the v22.2.1 release of the Support Design Library.

    0 讨论(0)
提交回复
热议问题