RT:
private ImageView animation;
    private AnimationDrawable animationDrawable;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xml);
       animation=(ImageView) findViewById(R.id.animation);
        
       animation.setImageResource(R.drawable.huanyin);
       animationDrawable=(AnimationDrawable) 
       animation.getDrawable(); 
       animationDrawable.start(); 
运行不起来啊

解决方案 »

  1.   

    http://blog.csdn.net/liuhanhan512/article/details/7666821
      

  2.   

    R.drawable.huanyin
    发上来看看。
      

  3.   

    animation.setBackgroundResource(R.drawable.huanyin);
      animationDrawable=(AnimationDrawable) animation.getBackground();  
      animationDrawable.start(); 换成这样试一下呢
      

  4.   

    public class Activity11 extends Activity { private AnimationDrawable animDrawable;
    private ImageView stage;
    private Button start;
    private Button stop; @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity11); stage = (ImageView) findViewById(R.id.imageview);
    animDrawable = new AnimationDrawable(); for (int i = 1; i <= 20; i++) {
    int resId = getResources().getIdentifier(
    "anim" + (i > 9 ? "_" : "_0") + i, "drawable",
    "com.tarena.tts");
    animDrawable.addFrame(getResources().getDrawable(resId), 150);
    }
    animDrawable.setOneShot(false);
    stage.setImageDrawable(animDrawable); start = (Button) findViewById(R.id.start);
    stop = (Button) findViewById(R.id.stop); start.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    animDrawable.start();
    }
    }); stop.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    animDrawable.stop();
    }
    });
    }
    }
      

  5.   

    我是想动画完了直接转下个actvtity,,看了二楼的知道了必须有事件才能启动动画也成功了,但我用的是线程启动改成这样报异常。。麻烦各位帮忙看下
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.drawable.AnimationDrawable;
    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 Androd_DHJMActivity extends Activity
    {
        /** Called when the activity is first created. */    private ImageView animation;
        private AnimationDrawable animationDrawable;
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.xml);
            animation = (ImageView) findViewById(R.id.animation);
        }
        @Override
        protected void onResume()
        {
            super.onResume();
            Animation anim = AnimationUtils.loadAnimation(this, R.drawable.huanyin);
            if (anim != null)
            {
                anim.setAnimationListener(new AnimationListener() {                @Override
                    public void onAnimationStart(Animation animation)
                    {                }
                    @Override
                    public void onAnimationRepeat(Animation animation)
                    {                }
                    @Override
                    public void onAnimationEnd(Animation animation)
                    {
                        Intent intent = new Intent();                    intent.setClass(Androd_DHJMActivity.this, Main.class);                    Androd_DHJMActivity.this.startActivity(intent);                    Androd_DHJMActivity.this.finish();
                    }
                });
                animation.startAnimation(anim);
            }
        }}
      

  6.   

    R.drawable.huanyin 格式不对了这个是不能用animation-list的