Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RecyclerView快速滚动,持续减速_Android_Android Recyclerview - Fatal编程技术网

Android RecyclerView快速滚动,持续减速

Android RecyclerView快速滚动,持续减速,android,android-recyclerview,Android,Android Recyclerview,我想更改我的水平回收视图的平滑滚动位置行为 一开始应该很快,我已经做到了 不断地降低速度,最终平滑地滚动到目标元素。这是我没有做到的 过度使用calculateTimeForDeceleration方法对我没有帮助,这听起来应该会减慢速度 CustomLinearLayoutManager代码: CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager(this, LinearLayoutManager.H

我想更改我的水平回收视图的平滑滚动位置行为

  • 一开始应该很快,我已经做到了
  • 不断地降低速度,最终平滑地滚动到目标元素。这是我没有做到的
过度使用calculateTimeForDeceleration方法对我没有帮助,这听起来应该会减慢速度

CustomLinearLayoutManager代码:

CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false, 0.4f);
galleryView = findViewById(R.id.recyclerview);
galleryView.setLayoutManager(layoutManager);
自定义LinearLayoutManager:

public class CustomLinearLayoutManager extends LinearLayoutManager {
    private final float factor;


    public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout, float factor) {
        super(context, orientation, reverseLayout);
        this.factor = factor;
    }

    @Override
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

        final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

            @Override
            public PointF computeScrollVectorForPosition(int targetPosition) {
                return CustomLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
            }

            @Override
            protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                return super.calculateSpeedPerPixel(displayMetrics) * factor;
            }

            @Override
            protected int calculateTimeForScrolling(int dx) {
                return super.calculateTimeForScrolling(dx*1);
            }

        };

        linearSmoothScroller.setTargetPosition(position);
        startSmoothScroll(linearSmoothScroller);
    }

    @Override
    public void scrollToPosition(int position) {
        super.scrollToPosition(position);
    }
}
如何持续降低滚动速度