帧动画无限运行

时间:2014-09-22 18:40:27

标签: android xml animation

我有一个xml帧动画,我希望它只运行一次..但它会无限运行..即使我使用isOneShot()

这是我的代码

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import de.vrallev.tutorial.dialer.R;

public class testanim extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.animtest);
        ImageView iv = (ImageView) findViewById(R.id.imageView1);
        iv.setImageBitmap(null);
        iv.setBackgroundResource(R.anim.animation);

        final AnimationDrawable mailAnimation = (AnimationDrawable) iv
                .getBackground();
        mailAnimation.isOneShot();
        mailAnimation.start();

1 个答案:

答案 0 :(得分:0)

我猜你误解了方法isOneShot()。此方法返回动画是否仅播放一次。如果要将动画设置为仅在必须调用方法setOneShot (booleanValue)时运行 所以在你的情况下写下这样的东西:mailAnimation.setOneShot(true)

也请参阅有关此主题的文档(click)。