Android NestedScrollView has wrong size after app:layout_behavior

后端 未结 4 1371
眼角桃花
眼角桃花 2020-12-13 04:49

Since Google has published the design support library for android, there are many nice things that can be done without implementing custom code. While i\'ve tested the custo

4条回答
  •  孤街浪徒
    2020-12-13 05:26

    I had this problem and fixed adding:

    android:layout_gravity="fill_vertical"
    

    to the NestedScrollView. Then it starts behaving correctly, as I explained here also. Of course the NestedScrollView needs some kind of child (i.e. it must not be empty), otherwise the toolbar won't collapse.

    Update

    While this works well with small content, I noticed it has some problems showing longer contents, e.g. like the full activity_detail.xml above. The problem is that you can't scroll to the very bottom part of the content - it is unreachable at the bottom.

    From my tests I could find that the missing part is as big as the collapsed toolbar (or at least that's what it looks to me). To fix this is issue, and having a solution reliable for both small and big contents, you should add a layout_marginBottom to the ScrollView, so that it gets measured and releases the missing bottom part. Thus:

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

    or whatever size you gave to the Toolbar.

    But still

    Scrolling with small contents with this solution, even if the content is justly aligned at the top, isn't really smooth as scrolling with large contents. I'll use until a library fix comes.

    Update2

    Looks like this was fixed in v22.2.1 .

提交回复
热议问题