自API 24起,
在
RecyclerView
将在用户点击部分显示的项目时自动滚动到该项目。
如何禁用此功能?在
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
,文本需要可选择。
YourFocusableChildViewClass
? - Aldan