我RecyclerView用来查看我的数据,但是当有很多项目时,RecyclerView每次插入新项目时都会自动滚动到底部。如何预防?
这是插入代码:
@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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是 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>
Run Code Online (Sandbox Code Playgroud)