You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RecyclerView删除Item时动画异常的问题及平滑实现方案咨询

RecyclerView删除Item时动画异常的问题及平滑实现方案咨询

我现在做了一个展示地点列表的RecyclerView,需求是点击每条Item上的删除图标按钮,就把对应的Item删掉。目前我写的代码确实能实现删除功能,但执行删除后的动画效果完全不对,不是我想要的那种平滑过渡。

我先贴一下当前onBindViewHolder里的代码:

override fun onBindViewHolder(holder: ViewHolder, position: Int) {

    holder.locationTitleTextView.text = locationList[position].name

    holder.coordinatesTextView.text = locationList[position].coordinateText

    holder.deleteLocationButton.setOnClickListener {

        locationList.removeAt(position)

        notifyItemRemoved(position)

        notifyItemRangeChanged(position, locationList.size)

    }
}

具体的异常动画表现是这样的:当我删除非最后一项的时候,列表的最后一项会先变成不可见,然后整个列表像是瞬间刷新了一遍,动画非常生硬,完全没有预期的平滑删除过渡效果。

想请教下各位,有没有什么其他的实现方式,能让Item删除时的动画变得平滑自然,不会出现这种突兀的情况?

备注:内容来源于stack exchange,提问作者Goutham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 14:23:10