绘制圆角笔划动画

问题描述

当前正在研究Canvas并绘制自定义视图。我刚刚用此代码(我的onDraw方法)创建了一个带有边框的圆形矩形:

paint.color = Color.RED
paint.style = Paint.Style.FILL
val cornerRadius = 150f
val strokeWidth = 12f
val rect = RectF(
   rootView.left.toFloat() + strokeWidth,rootView.top.toFloat() + strokeWidth,rootView.right.toFloat() - strokeWidth,rootView.bottom.toFloat() - strokeWidth
)
canvas.drawRoundRect(rect,cornerRadius,paint)
paint.style = Paint.Style.stroke
paint.color = Color.GREEN
paint.strokeWidth = strokeWidth
canvas.drawRoundRect(rect,paint)

我要实现的是此边框的动画(蛇状进度)。上次我做类似的事情是圆形边框动画,其中drawArc对象中具有动态变化角度的Animation做得很好。但是,这次我不能使用drawArc,因为需要不同的形状。我在要指出动画开始位置的位置附加图像。我当时正在考虑创建Path对象,但是我不知道如何从右下角开始绘制(仅在圆角部分之后)。有人已经使用类似的东西了吗?

上次(对于圈子,如前所述),我做了这样的事情:

canvas.drawArc(rect,START_ANGLE_POINT,angle,false,paint)

和Animation类:

    private inner class CountdownAnimation(private val roundCountdownView: RoundCountdownView): Animation() {

        override fun applyTransformation(interpolatedTime: Float,t: Transformation?) {
            roundCountdownView.angle = 360f * interpolatedTime
            roundCountdownView.requestLayout()
        }
    }

我想达到类似的目的,但是在互联网上找不到任何有用的东西。已经找到this SO question,但我认为通过位图完成此操作对于此特定问题而言是过大的。我将不胜感激任何建议。提前致谢! :)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)