gpt4 book ai didi

android - 在不调用适配器上的 notifyItemChanged(int) 的情况下更新 RecyclerView 项目 ProgressBar

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:52:00 27 4
gpt4 key购买 nike

我正在尝试更新一个 progressBar,它是 RecyclerView 项目之一的一部分。我知道我可以通过两种方式做到这一点,

方法一:通过调用notifyItemChanged(position)刷新item行

方法 2:通过使用 LayoutMananger 对象上的 findViewByPosition() 方法访问 View 。

但不幸的是,它们都不适用于我的情况。

如果我使用第一个,整个项目将被重新绘制,recyclerview 的背景颜色为灰色,项目为白色,因此用户可以注意到整个项目刷新。

如果我尝试第二个,我最终会在滚动时遇到问题。

我想像 WhatsApp 一样更新进度。提前致谢

最佳答案

If I use the first one, the whole item will get repainted, the background color of the recyclerview is gray and the item is white, so the user can notice the whole item refresh.

我也遇到了这个问题。要修复它,您需要关闭默认的项目更改动画。关闭项目更改动画后,您的 recyclerView 项目将更新而不会出现任何闪烁/跳跃,从而使您可以毫无问题地使用 notifyItemChanged(int)

像这样关闭默认的项目更改动画:

((SimpleItemAnimator) myRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

关于android - 在不调用适配器上的 notifyItemChanged(int) 的情况下更新 RecyclerView 项目 ProgressBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38568044/

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