API 19 Scrollview no momentum

前提是你 提交于 2019-12-04 16:23:32

I was able to recreate your symptoms in my test project. I fixed it be adding the following code in onCreate() for the activity:

final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setOnFlingListener(new RecyclerView.OnFlingListener() {
        @Override
        public boolean onFling(int velocityX, int velocityY) {
            recyclerView.dispatchNestedFling(velocityX, velocityY, false);
            return false;
        }
    });

I added a fling listener to the RecyclerView, and in onFling(), I call dispatchNestedFling() to let the parent know that a fling is occurring. The parent can then consume the fling or observe the child fling.

https://developer.android.com/reference/android/support/v4/view/NestedScrollingChild.html#dispatchNestedFling(float, float, boolean)

dispatchNestedFling

added in version 22.1.0 boolean dispatchNestedFling (float velocityX, float velocityY, boolean consumed) Dispatch a fling to a nested scrolling parent.

This method should be used to indicate that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.

If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.

This is working on my emulator running API 19. Obviously, YMMV.

There is a simpler way:

Java

recyclerView.setNestedScrollingEnabled(false);

Kotlin

recyclerView.isNestedScrollingEnabled = false
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!