Reputation: 43
I want to make a rotate animation for my view but in both sides (java and xml) I cant find any way to rotate view from it's centre
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="180" />
and this:
RotateAnimation animation = new RotateAnimation(0,180,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
both of them rotate view from its corner
please help me
Upvotes: 2
Views: 6736
Reputation: 438
Looks like you try rotate all layout, not view. That you need. worked code
View view = findViewById( R.id.image );
aRotate = new RotateAnimation(fStartAngle, fEndAngle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
aRotate.setStartOffset(0);
aRotate.setDuration(2000);
aRotate.setFillAfter(true);
aRotate.setInterpolator(context, android.R.anim.decelerate_interpolator);
view.startAnimation(aRotate);
Upvotes: 11