在 SurfaceView 中使用 Drawable 创建旋转动画

Create a rotation animation with a Drawable in SurfaceView

我有一个 Drawable(矢量),我想为它制作像轮子一样旋转的动画。我该如何解决这个问题?

这是我能找到的唯一与我的问题类似的问题,但问题是答案不适用于 VectorDrawables:Animating and rotating an image in a Surface View

我没有任何代码可以显示,因为我什至不知道从哪里开始。我需要一些指导。

您可以将 VectorDrawable 转换为位图,然后使用 link 的解决方案。

private Bitmap getBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
                vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}