Seamless nested scrolling (Android)

前端 未结 8 1477
不知归路
不知归路 2020-12-15 01:46

We\'ve all been advised against nesting views that contain a scrolling mechanism. However, in the latest Android release (5.0), the Phone app caught my attention with what s

8条回答
  •  渐次进展
    2020-12-15 02:08

    Android 5.0 Lollipop (API 21) added nested scrolling support.

    From what I can tell, both ListView (AbsListView) and ScrollView support this now (if running on API 21), but it must be enabled on the scrolling views.

    There are two ways, by calling setNestedScrollingEnabled(true) or with the layout attribute android:nestedScrollingEnabled="true" (which is undocumented)

    To learn about how it works, or to support this for a custom widget, the key methods are these:

    • onStartNestedScroll

    • onNestedScrollAccepted

    • onNestedPreScroll

    • onNestedScroll

    • onStopNestedScroll

    Unfortunately, there is no guide or training which explains how this works other than the JavaDoc itself which is rather light and there are no examples other than ScrollView.

提交回复
热议问题