![](/img/trans.png)
[英]Android/Java: How to disable auto-scroll when RecyclerView visibility goes from GONE to VISIBLE
[英]Android - How to disable RecyclerView auto scroll from clicking
从API 24开始, RecyclerView
将自动滚动到用户点击该项目部分显示的项目。 如何禁用此功能?
以下代码在support-library 25.0.1
之前support-library 25.0.1
。
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
Object tag = child.getTag();
if( tag != null && tag.toString().equalsIgnoreCase("preventAutoScroll") ){
return false;
}
return super.requestChildRectangleOnScreen(child, rect, immediate);
}
它必须是可聚焦和可点击的,因为它是一个TextView
,文本需要是可选择的。
在回收器视图上设置布局管理器的覆盖版本。 在我的情况下,我想禁用某个特定的儿童视图时,例如
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context) {
@Override
public boolean requestChildRectangleOnScreen(RecyclerView parent, View child, Rect rect, boolean immediate, boolean focusedChildVisible) {
if (((ViewGroup) child).getFocusedChild() instanceof YourFocusableChildViewClass) {
return false;
}
return super.requestChildRectangleOnScreen(parent, child, rect, immediate, focusedChildVisible);
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.