I want to rotate imageview with continuously looping on android.my code rotate is working perfectly with out set repeat mode.if i set repeat mode repeat animation not working but, imageview statically rotate some angle and i want loop rotate animation any one can help me with greatly appreciated!
here's animation xml
<?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="100"
android:startOffset="0"
/>
here's my java class
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class AnimationActivity extends Activity {
/** Called when the activity is first created. */
ImageView my_image;
AnimationListener listener;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listener = new AnimationListener() {
@Override public void onAnimationStart(Animation animation) {}
@Override public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
System.out.println("End Animation!");
//load_animations();
}
};
my_image=(ImageView)findViewById(R.id.my_img);
load_animations();
}
void load_animations()
{
new AnimationUtils();
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
rotation.setRepeatCount(-1);
rotation.setRepeatMode(2);
rotation.setAnimationListener(listener);
my_image.startAnimation(rotation);
}
}
Thanks in Advance!
In android, Rotate animation is used to change the appearance and behavior of the objects over a particular interval of time. The Rotate animation will provide a better look and feel for our applications.
android.view.animation.RotateAnimation. An animation that controls the rotation of an object. This rotation takes place in the X-Y plane. You can specify the point to use for the center of the rotation, where (0,0) is the top left point. If not specified, (0,0) is the default rotation point.
finally,i got solution try below xml:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
android:repeatMode="reverse"
android:repeatCount="infinite"
android:startOffset="0"
/>
here's my class
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class AnimationActivity extends Activity {
/** Called when the activity is first created. */
ImageView my_image;
AnimationListener listener;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listener = new AnimationListener() {
@Override public void onAnimationStart(Animation animation) {}
@Override public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
System.out.println("End Animation!");
//load_animations();
}
};
my_image=(ImageView)findViewById(R.id.my_img);
load_animations();
}
void load_animations()
{
new AnimationUtils();
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
rotation.setAnimationListener(listener);
my_image.startAnimation(rotation);
}
}
That's the code is working perfectly!
My problem was solved!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With