khan
khan

Reputation: 935

how can i stop animation

how can i stop the animation ..this is my code

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class animation extends Activity {

    ImageView img;
    Animation an;
    Button bt;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        img = (ImageView)findViewById(R.id.ImageView01);
        an = AnimationUtils.loadAnimation(this, R.anim.anim);
        bt= (Button)findViewById(R.id.Button01);

        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                img.startAnimation(an);
            }
        });
    }
}

Upvotes: 3

Views: 13916

Answers (2)

user914505
user914505

Reputation: 71

I assume your Animation (an) runs infinitely. When you want that to stop use img.clearAnimation();.

Upvotes: 7

WarrenFaith
WarrenFaith

Reputation: 57672

You should start looking in the API, its the first mentioned method there:

http://developer.android.com/reference/android/view/animation/Animation.html

Upvotes: 0

Related Questions