如何使用“RotateDrawable”?如何使用、RotateDrawable

2023-09-05 08:24:23 作者:爷不死你永远是个孙子

谁能告诉我,他们是如何得到RotateDrawable的工作,无论是从code或XML或两者兼而有之?关于动画可绘制的文档是pretty的穷人和动漫似乎只工作图像。我希望能够以动画的所有可绘制。当我试图从XML获得RotateDrawble只是导致异常。什么是正确的函数找到一个RotateDrawable从XML?

Could anyone tell me how they have got 'RotateDrawable' to work whether it be from code or XML or both? The documentation on animating Drawables is pretty poor and animation only seems to work for images. I want to be able to animate all drawables. When i tried to get a RotateDrawble from XML is just causes an exception. What is the correct function to find a RotateDrawable from XML?

感谢

Kerubu

推荐答案

RotateDrawable似乎不被动画。相反,你必须使用执行setLevel来改变绘制的旋转。

RotateDrawable does not seem to be animated. Instead, you have to use setLevel to change the rotation of the drawable.

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/your_drawable"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" />

和设置的级别都会将绘制:

And set the level will rotate the drawable:

final ImageView image = (ImageView)findViewById(R.id.imageView1);
final RotateDrawable drawable = (RotateDrawable)image.getDrawable();
drawable.setLevel(500);