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

问题描述 投票:0回答:1

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

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

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

android surfaceview android-drawable android-vectordrawable
1个回答
0
投票

您可以将VectorDrawable转换为Bitmap,而不是使用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;
}
© www.soinside.com 2019 - 2024. All rights reserved.