Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to disable RecyclerView auto scroll from clicking

Since API 24, the RecyclerView will auto scroll to a item which is displayed in partial by the user click the item. How to disable this feature?

The codes below works before 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);
    }

It has to be focusable and clickable, because it's a TextView and the text needs to be selectable.

like image 291
Kimi Chiu Avatar asked Oct 29 '25 03:10

Kimi Chiu


1 Answers

Set an overriden version of the layout manager on recycler view. In my case I wanted to disable for when a certain child view was focused e.g.

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);
        }
    };
like image 148
user7768828 Avatar answered Oct 31 '25 19:10

user7768828



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!