Android-RotateAnimation-从度到度变量

Android-RotateAnimation-从度到度变量,android,xml,variables,rotateanimation,Android,Xml,Variables,Rotateanimation,我是Android新手,有点小问题。 我找到了RotateAnimation的以下代码: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <rotate andro

我是Android新手,有点小问题。 我找到了RotateAnimation的以下代码:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="20000"
        android:startOffset="0"/>
</set>
存储RotateAnimation所有数据的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="20000"
        android:startOffset="0"/>
</set>
如何在xml文件中创建这两个值的变量

    android:fromDegrees="0"
    android:toDegrees="360"

请尝试以下代码,它可能会工作:

       <?xml version="1.0" encoding="utf-8"?>
        <rotate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="45"
        android:toDegrees="45"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="0"
        android:startOffset="0"
        />
试试另一个:

     Matrix matrix=new Matrix();
 imageView.setScaleType(ScaleType.MATRIX);   //required
 matrix.postRotate((float) angle, pivX, pivY);
 imagView.setImageMatrix(matrix);

根据RotateAimation类参考(http://developer.android.com/reference/android/view/animation/RotateAnimation.html),此类不为fromDegrees和toDegrees提供setter方法。因此,如果需要在代码中设置这些值,则必须在代码中创建RotateAnimation对象,并将fromDegrees和toDegrees值传递到构造函数中

RotateAnimation rotateAnimation = new RotateAnimation(fromDegrees, toDegrees);

**强文本**

在“值”文件夹中使用带有预定义整数的xml文件。Android说文件名无关紧要,但你也可以把它放在一个名为
res/values/integers.xml
的文件中。有关此类型xml文件的详细信息。基本上,将度值作为整数放在
integers.xml
中,在旋转xml代码中使用它们,然后使用
getResources().getInteger()
在活动代码中检索它们。下面是示例代码:

integers.xml
中:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="from_degrees">0</integer>
    <integer name="to_degrees">360</integer>
</resources>
在java代码中:

int fromDegrees = getResources().getInteger(R.integer.from_degrees);
int toDegrees = getResources().getInteger(R.integer.to_degrees);

我想你还没有理解我的问题。。。我想把fromDegree和toDegree值放在一个变量中。。。谢谢,谢谢,但我更喜欢“我的”代码,如果可能的话,把值放在一个变量中。。。谢谢你,我知道了。如何在最终动画myRotation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotator)上实现这一点?虽然这段代码可以回答这个问题,但提供关于它如何和/或为什么解决问题的附加上下文将提高答案的长期价值。
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="from_degrees">0</integer>
    <integer name="to_degrees">360</integer>
</resources>
...
android:fromDegrees="@integer/from_degrees"
android:toDegrees="@integer/to_degrees"
...
int fromDegrees = getResources().getInteger(R.integer.from_degrees);
int toDegrees = getResources().getInteger(R.integer.to_degrees);