gpt4 book ai didi

android - 带偏移量的 RecyclerView 滚动速度

转载 作者:行者123 更新时间:2023-11-29 02:42:19 34 4
gpt4 key购买 nike

我想将我的 RecyclerView 滚动到具有 offset 的特定位置。现在我正在使用 scrollToPositionWithOffset(position, offset) 并且这个方法工作正常,除了滚动发生得太快而且我无法控制滚动的速度。我试过使用 smoothScrollToPosition() 但我需要偏移量。有人能告诉我如何在使用 scrollToPositionWithOffset() 时控制滚动速度吗?

最佳答案

如果需要控制fling速度,需要自己实现recyclerview实现。

public class CustomRecyclerView extends RecyclerView {

Context context;

public CustomRecyclerView(Context context) {
super(context);
this.context = context;
}

public CustomRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public CustomRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
public boolean fling(int velocityX, int velocityY) {

velocityY *= 0.7;
// velocityX *= 0.7; for Horizontal recycler view. comment velocityY line not require for Horizontal Mode.

return super.fling(velocityX, velocityY);
}

}

关于android - 带偏移量的 RecyclerView 滚动速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43255701/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com