gpt4 book ai didi

java - 如何删除 Android 回收器 View 中删除项目后留下的空白空间?

转载 作者:行者123 更新时间:2023-12-01 09:06:54 25 4
gpt4 key购买 nike

我有一个非常简单的回收 View ,具有以下布局:-

  <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>

我的回收站 View 布局如下:-

<?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"
/>

这是我用来从回收器 View 中删除该项目的代码:-

 private void removeItem(UserInfo list) {
int current_position = listData.indexOf(list);
listData.remove(current_position);
notifyItemRemoved(current_position);
}

我的线性布局位于 ScrollView 内。现在,当我删除回收器 View 内的项目时,该项目将被删除,但删除后留下空白空间。当回收器 View 内的项目时,如何自动删除此空间被删除了吗?

感谢任何帮助或建议。谢谢。

最佳答案

尝试添加notifyItemRangeChanged(int, int)在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());
}

关于java - 如何删除 Android 回收器 View 中删除项目后留下的空白空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41196903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com