Java 如何删除android回收器视图中删除项目后留下的空白空间?
我有一个非常简单的recyclerview,布局如下:-Java 如何删除android回收器视图中删除项目后留下的空白空间?,java,android,xml,layout,android-recyclerview,Java,Android,Xml,Layout,Android Recyclerview,我有一个非常简单的recyclerview,布局如下:- <LinearLayout android:id="@+id/address_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" >
<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>
我的线性布局在滚动视图中。现在,当我删除回收器视图中的项目时,该项目会被删除,但删除后会留下空白。删除回收器视图中的项目时,如何自动删除该空间
非常感谢您的帮助或建议。谢谢。尝试添加notifyItemRangeChanged(int,int) 删除NOTIFYItem后(当前位置)
可能您将setHasFixedSize设置为true,因此尝试将其设为false setHasFixedSize(false),它将删除该空间我尝试了您的解决方案,但删除后仍有空空间?recyclerview项布局是什么样的?您的适配器和viewholder是什么样的?删除项后调试并检查列表的大小是否减少1。还可以尝试notifyDataSetChanged()太好了!!为我工作
<?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"
/>
private void removeItem(UserInfo list) {
int current_position = listData.indexOf(list);
listData.remove(current_position);
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());
}