Android ItemTouchHelper:如何在滑动时画出越来越大的圆圈

Android ItemTouchHelper: How to draw growing circle during Swipe

我正在使用 ItemTouchHelper 触发 RecylcerView 项目的滑动操作。滑动时,从中间点开始,背景中应该出现一个圆圈,并且这个圆圈应该越来越大,直到整个项目变成圆圈的颜色。

结果应如下所示:

目前我正在使用 ItemTouchHelper

onChildDraw 方法
override fun onChildDraw(c: Canvas,recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder,
dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) {

...

val backgroundGrey = ColorDrawable()
backgroundGrey.Color.parseColor("#CFD8DC")
backgroundGrey.setBounds(
    itemView.right + dx,
    itemView.top,
    itemView.right,
    itemView.bottom
)
backgroundGrey.draw(c)

val itemHeight = itemView.bottom - itemView.top
val iconTop = itemView.top + (itemHeight - icon.intrinsicHeight) / 2
val iconMargin = (itemHeight - icon.intrinsicHeight) * 2
val iconLeft = itemView.right + iconMargin - icon.intrinsicWidth + dx
val iconRight = itemView.right + iconMargin + dx
val iconBottom = iconTop + icon.intrinsicHeight

val circle = GradientDrawable()
circle.shape = GradientDrawable.OVAL
circle.cornerRadii = floatArrayOf(0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f)
circle.setColor(Color.parseColor("#ba000d"))

cirle.setBounds(iconLeft, iconTop, iconRight, iconBottom) // Size like Icon
//cirle.setBounds(itemView.right + dx, itemView.top, itemView.right,itemView.bottom) // circle gets stretched
//cirle.setBounds(0, 0, 1500,1500) // circle overlaps other recyclerview items
cirle.draw(c)

val icon = ContextCompat.getDrawable(context, R.drawable.ic_baseline_delete_24)
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom)
icon.draw(c)

}

我尝试了不同的方法,但 none 带来了预期的结果。 各种结果如下所示:

有谁知道如何从顶部图像中获得结果?

您可能需要在 canvas 上夹上一个夹子,然后再按照描述绘制圆圈,例如在 here.