Reputation: 13
Is there any way to create a ray animation behind buttons in Android like this https://davidwalsh.name/javascript-spin
It should just rotate behind the coin.
That rays should rotate within the rectangle of the parent layout. Any easy way to do it?
My code:
final Animation animRotate = AnimationUtils.loadAnimation(context,R.anim.image_rotate);
ImageView rl2=(ImageView) view.findViewById(R.id.ss);
rl2.startAnimation(animRotate);
and xml file:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="10000"
android:repeatMode="restart"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%">
</rotate>
</set>
Upvotes: 1
Views: 1466
Reputation: 5741
Rotate your background image with respect to pivot point, pivot point will be center point of image.
ImageView img = (ImageView) view.findViewById(R.id.ss);
RotateAnimation rotateAnimation = new RotateAnimation(0f,360f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setRepeatCount(Animation.INFINITE);
img.startAnimation(rotateAnimation);
Upvotes: 1
Reputation: 313
You can use objectAnimator to achieve this.
<objectAnimator
android:duration="3000"
android:propertyName="rotation"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:valueTo="360"
android:valueType="floatType" />
And one more thing accelerate_decelerate_interpolator makes the animation speed up at the start and slow down at the end.
Upvotes: 1