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 ?
this is the insert code:
@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);
}
});
}
this the the 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>
Try using
android:descendantFocusability="blocksDescendants"
in recyclerview. This will help you avoid autoscroll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With