RecyclerView带偏移量的滚动速度
问题描述:
我想滚动我的RecyclerView
到offset
的特定位置。现在我正在使用scrollToPositionWithOffset(position, offset)
并且此方法可以正常工作,除非滚动发生得太快,而且我无法控制滚动的速度。我试过使用smoothScrollToPosition()
,但我需要偏移量。有人能告诉我如何在使用scrollToPositionWithOffset()
时控制滚动速度?RecyclerView带偏移量的滚动速度
答
把你的recyclerview
放在nestedScrollview
它会顺利滚动。
答
如果您需要控制投掷速度,则需要实施自己的回收器视图实现。
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);
}
}
哇......我的工作一切都很顺利,请问您能告诉我您是如何使用它的? *好奇* –
尽管这可能会回答这个问题,但提供关于_how_和/或_why_的附加[上下文](https://meta.stackexchange.com/q/114762)可以解决问题,从而提高答案的长期价值。请记住,你正在为将来的读者回答这个问题,而不仅仅是现在问的人!请[编辑](http://*.com/posts/43255822/edit)您的答案添加一个解释,并指出适用的限制和假设。它也不会提到为什么这个答案比别人更合适。 –