插入新项目时如何防止recyclerview自动滚动到底部? [英] how to prevent recyclerview auto scroll to bottom when insert new items?

查看:406
本文介绍了插入新项目时如何防止recyclerview自动滚动到底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RecyclerView来查看我的数据,但是当有很多项目时,RecyclerView会在每次插入新项目时自动滚动到底部.如何预防呢?

I am using RecyclerView to view my data, but when there are many items ,RecyclerView will auto scroll to the bottom everytime a new item is inserted. how to prevent it ?

这是插入代码:

 @Override
            public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

                getOneMessage(dataSnapshot.getKey(), new OneMessageCallBack() {
                    @Override
                    public void OnCallBack(Object_Message message) {

                        Object_Conversation conversation=new Object_Conversation(dataSnapshot.getKey(),message);

                        mConvers_List.add(conversation);
                        mConvers_Adapter.notifyItemInserted(mConvers_List.size()-1);


                    }
                });

            }

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_conversations"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:background="@color/white">

    </android.support.v7.widget.RecyclerView>

</LinearLayout>

推荐答案

尝试使用

android:descendantFocusability="blocksDescendants"

在recyclerview中.这将帮助您避免自动滚动

in recyclerview. This will help you avoid autoscroll

这篇关于插入新项目时如何防止recyclerview自动滚动到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆