我怎么能停止动画

时间:2011-02-16 12:32:21

标签: android animation

我怎么能停止动画..这是我的代码

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);
            }
        });
    }
}

2 个答案:

答案 0 :(得分:7)

我假设您的动画(an)无限运行。如果您希望停止使用img.clearAnimation();

答案 1 :(得分:0)

你应该开始查看API,它是第一个提到的方法:

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