0 votes
78 views
asked in JAVA by

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 by (8.2k 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());

Categories

...