Search code examples
androidandroid-5.0-lollipop

What are the new nested scrolling APIs for Android-L?


I'm unable to find this info at https://developer.android.com/preview/api-overview.html

Thanks!


Solution

  • They did not draw much attention to this great new feature. I've been toying with it, and I think I've figured it out. All you have to do is is set

    android:nestedScrollingEnabled="true"

    in the nested (child) scrollable view, assuming you have one somewhere inside another. This causes the child view to scroll to completion, and then allow its parent to consume the rest of the scroll. I found that I liked the opposite behavior better - parent gets scroll priority, then child follows - so I overrode the onNestedScroll method in ScrollView as follows:

    @Override
    public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        //swap dyConsumed and dyUnconsumed
        super.onNestedScroll(target, dxConsumed, dyUnconsumed, dxUnconsumed, dyConsumed);
    }
    

    You should use this new ScrollView subclass for the outer (parent) ScrollView.