Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Rotate animation Looping not work on android

Tags:

android

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!

like image 557
Dinesh Avatar asked Jun 26 '12 10:06

Dinesh


People also ask

What is rotate animation in Android?

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.

What is animation rotation?

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.


1 Answers

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!

like image 184
Dinesh Avatar answered Sep 20 '22 03:09

Dinesh