gpt4 book ai didi

android - 调用 notifyitemchanged 后的动画问题

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:49 25 4
gpt4 key购买 nike

我有一个 ImageView,其中使用 Glide 加载图像。当我执行了 like 操作后,使用 notifyItemChanged(position) 通知回收器 View 适配器。它会导致图像闪烁 2 次。任何人都可以在这里帮助我。

这部分代码在 notifyItemChanged(position) 被调用时执行:

    Glide.with(mContext)
.load(mainImage)
.placeholder(R.color.grey_light)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(listItemHolder.mSingleAttachmentImage);

提前致谢。

最佳答案

方案一:

ItemAnimator animator = mRecyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}

ref https://github.com/bumptech/glide/issues/1599


方案二:

notifyItemChanged(int position) > notifyItemRangeChanged(int positionStart, int itemCount) > notifyItemRangeChanged(positionStart, itemCount, null) ;

/**
* Notify any registered observers that the item at <code>position</code> has changed with an
* optional payload object.
*
* <p>This is an item change event, not a structural change event. It indicates that any
* reflection of the data at <code>position</code> is out of date and should be updated.
* The item at <code>position</code> retains the same identity.
* </p>
*
* <p>
* Client can optionally pass a payload for partial change. These payloads will be merged
* and may be passed to adapter's {@link #onBindViewHolder(ViewHolder, int, List)} if the
* item is already represented by a ViewHolder and it will be rebound to the same
* ViewHolder. A notifyItemRangeChanged() with null payload will clear all existing
* payloads on that item and prevent future payload until
* {@link #onBindViewHolder(ViewHolder, int, List)} is called. Adapter should not assume
* that the payload will always be passed to onBindViewHolder(), e.g. when the view is not
* attached, the payload will be simply dropped.
*
* @param position Position of the item that has changed
* @param payload Optional parameter, use null to identify a "full" update
*
* @see #notifyItemRangeChanged(int, int)
*/
public final void notifyItemChanged(int position, Object payload) {
mObservable.notifyItemRangeChanged(position, 1, payload);
}

注意@param payload 可选参数,使用null来标识“完整”更新

您可以使用 notifyItemChanged(position,position) 并在 RecyclerView.Adapter.onBindViewHolder() 中执行 changeView

关于android - 调用 notifyitemchanged 后的动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38196512/

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