rotateing without using XML animation file

0 votes
70 views
asked Nov 17, 2013 in JAVA by Farzad19

i want rotate a image without use xml file.

it is my xml animation code:

<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="10000"
android:fillAfter="false"
android:startOffset="0"
android:interpolator="@android:anim/linear_interpolator"
/>

 

1 Answer

0 votes
answered Nov 17, 2013 by admin (8,115 points)
View needRotateView;// That needRotateView must make sure had measured
    float w = needRotateView.getWidth();
    float h = needRotateView.getHeight();
    int type = Animation.RELATIVE_TO_SELF;//sorry,if not work find,try the follow type value
    // int value_type = Animation.RELATIVE_TO_PARENT;
    // int value_type = Animation.ABSOLUTE;
    RotateAnimation anim = new RotateAnimation(0, 360, type, w / 2, type,h / 2);
    anim.setDuration(1000 * 10);
    anim.setFillAfter(false);
    anim.setStartOffset(0);
    anim.setInterpolator(new LinearInterpolator());
...