Reputation: 605
I have a very simple recyclerview with the following layout:-
<LinearLayout
android:id="@+id/address_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include layout="@layout/address_recyclerview"></include>
</LinearLayout>
Wher my recycler view layout is as follows:-
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/adr_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
/>
This is the code I am using to delete the item from the recycler view:-
private void removeItem(UserInfo list) {
int current_position = listData.indexOf(list);
listData.remove(current_position);
notifyItemRemoved(current_position);
}
My Linear Layout is within a Scroll View.Now when I delete a item inside the recycler view the item gets deleted but after the deletion empty space is left behind.How do I auto delete this space when the item inside the recycler view is deleted?
Any help or suggestion is appreciated.Thank you.
Upvotes: 1
Views: 2127
Reputation: 133
Maybe you set setHasFixedSize to true, so try to make it false setHasFixedSize(false) and it will remove that space
Upvotes: 2
Reputation: 48
Try adding notifyItemRangeChanged(int, int) after notifyItemRemoved(current_position).
private void removeItem(UserInfo list) {
int current_position = listData.indexOf(list);
listData.remove(current_position);
notifyItemRemoved(current_position);
notifyItemRangeChanged (current_position, getItemCount());
}
Upvotes: 2