0

In my android project I have an image that i want to rotate it and create animation for long time. I can run program and it works fine. but I don't know how can I stop it. if you know please tell me.

Thanks

This is my code, I have a menu with two items, When I click on Start item, startAnimation function runs and when I click on Stop item, stopAnimation runs.:

public class Hypnagogic extends Activity 
{
    ImageView imView;
    Animation an;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        imView = (ImageView)findViewById(R.id.imView);
    }

    private void startAnimation()
    {
        an = AnimationUtils.loadAnimation(this, R.anim.spin);
        imView.startAnimation(an);
    }

    private void stopAnimation()
    {
        ;//there is no any stop function!
    }
}

also, in res/anim I put spin.xml that is my animation

<?xml version="1.0" encoding="utf-8"?>

<set>
    <rotate
    android:fromDegrees="0"
    android:toDegrees="-18000"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="50000" />
</set>

1 Answer 1

2

EDIT: I see. Okay, try the clearAnimation() method associated with the View class. You can call it directly on your ImageView, I'm almost certain this should work for your case:

imView.clearAnimation();

What have you tried? AnimationDrawable has a stop() method. You need to post how you're creating/starting the animation.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks dear kcoppock, I edited my question, please look at that. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.