如何删除在Android的回收站视图中删除项目后剩下的空白空间?

问题描述:

我有一个非常简单的recyclerview具有以下布局: -如何删除在Android的回收站视图中删除项目后剩下的空白空间?

<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我回收视图布局如下: -

<?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); 
    } 

我的线性布局是一种滚动View.Now内,当我删除回收站内的项目来查看该项目被删除BU t删除后留下空白空间。当回收站视图内的项目被删除时,如何自动删除此空间?

任何帮助或建议表示赞赏。谢谢。

+0

调试并检查删除项目后列表大小是否减1。 也试试notifyDataSetChanged() – Mrinmoy

尝试在notifyItemRemoved(current_position)之后添加notifyItemRangeChanged(int,int) 。

private void removeItem(UserInfo list) { 
    int current_position = listData.indexOf(list); 
    listData.remove(current_position); 
    notifyItemRemoved(current_position); 
    notifyItemRangeChanged (current_position, getItemCount()); 
} 
+0

我试过你的解决方案,但删除后仍然有空的空间? – anup

+0

什么是recyclerview项目布局?你的适配器和视图持有者喜欢什么? – julamme