【问题标题】:Android - How to disable RecyclerView auto scroll from clickingAndroid - 如何禁用 RecyclerView 自动滚动点击
【发布时间】:2017-04-03 10:47:19
【问题描述】:

自 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,并且文本需要是可选择的。

【问题讨论】:

    标签: android android-recyclerview


    【解决方案1】:

    在回收站视图上设置布局管理器的覆盖版本。就我而言,我想在某个子视图被聚焦时禁用,例如

    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);
            }
        };
    

    【讨论】:

    • 我RecyclerView里没有这个方法,你用第三方库吗?
    • 我在LayoutManager 中找到了它。像魅力一样工作!
    • 在哪里可以找到YourFocusableChildViewClass
    • YourFocusableChildViewClass =For Ex= > EditText
    猜你喜欢
    • 2021-08-13
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多