共享元素过渡,缩小图像时闪烁

Shared element transition, blink when scale down image

https://youtu.be/n8MdHNYozgs 我在片段和 activity 之间实现了共享元素转换,就像上面的视频

 val intent = Intent(context, Main2Activity::class.java)

    val list = ArrayList<Pair<View, String>>()
    (recyclerView.adapter as Adapter).list.forEachIndexed { index, entity ->
        val itemView = recyclerView.findViewHolderForAdapterPosition(index)?.itemView
        if (itemView != null) {
            list.add(Pair(itemView, entity.id.toString()))
        }
    }
    val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, *list.toTypedArray())
    startActivity(intent, options.toBundle())

在 activity 中,我在另一个回收站视图中显示视图。 你能给我一个建议,我应该怎么做才能避免在缩小图像结束时闪烁?

我找到了解决方案。问题是我使用 itemView 作为转换视图:

val itemView = recyclerView.findViewHolderForAdapterPosition(index)?.itemView
    if (itemView != null) {
        list.add(Pair(itemView, entity.id.toString()))
    }

但需要使用以下代码:

 val holder = MyRecyclerView.findViewHolderForAdapterPosition(index)
        if (holder != null) {
            with(holder as MyViewHolder) {
                list.add(Pair(this.image, entity.id.toString()))
            }
        }

一切正常。