package com.msi.manning.chapter9.xmlanimate;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class XMLAnimate extends Activity {
 private static MediaPlayer start_bgm;
  
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        ImageView img = (ImageView)findViewById(R.id.simple_anim);
        img.setBackgroundResource(R.anim.simple_animation);
        
        
        
        MyAnimationRoutine mar = new MyAnimationRoutine();
        MyAnimationRoutine2 mar2 = new MyAnimationRoutine2();
        
        Timer t = new Timer(false);
        t.schedule(mar, 20000);
        Timer t2 = new Timer(false);
        t2.schedule(mar2, 20000);
        
        start_bgm = MediaPlayer.create(this, R.raw.ost);
     start_bgm.setLooping(true);
     start_bgm.start();
     
     Button Btn_Start = (Button)findViewById(R.id.button1);
     Btn_Start.setOnClickListener(ButtonOnClick);
    }
    
    class MyAnimationRoutine extends TimerTask
    {
     @Override
     public void run()
     {
         ImageView img = (ImageView)findViewById(R.id.simple_anim);
            AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
            frameAnimation.start();
     }
    }
    
    class MyAnimationRoutine2 extends TimerTask
    {
         
     @Override
     public void run()
     {
         ImageView img = (ImageView)findViewById(R.id.simple_anim);
            AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
            frameAnimation.stop();
     }
    }
    private View.OnClickListener ButtonOnClick = new View.OnClickListener(){
    public void onClick(View v){
     switch(v.getId()){
     case R.id.button1:
      start_bgm.setLooping(false);
      start_bgm.stop();
      Intent ach = new Intent(XMLAnimate.this, Test.class);
      startActivity(ach);
      break;          
     }
  }
 };
// protected void onDestroy() {
//     super.onDestroy();
//
//     start_bgm.stop();
//     start_bgm.release();
//    }
//        
}


배경음이 재생되면서 배경은 재가 만든 이미지들로 프레임 하고싶은데.

배경음은 나오는데 프레임이미지들(1~5)중에 첫번째 이미지만 나오고 안되네요....

 <?xml version="1.0" encoding="utf-8" ?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" id="selected" android:oneshot="false">
  <item android:drawable="@drawable/s1" android:duration="150" />
  <item android:drawable="@drawable/s2" android:duration="150" />
  <item android:drawable="@drawable/s3" android:duration="150" />
  <item android:drawable="@drawable/s4" android:duration="150" />
  <item android:drawable="@drawable/s5" android:duration="150" />
  <item android:drawable="@drawable/s6" android:duration="150" />
  <item android:drawable="@drawable/s7" android:duration="150" />
  <item android:drawable="@drawable/s8" android:duration="150" />
  <item android:drawable="@drawable/s9" android:duration="150" />
  <item android:drawable="@drawable/s10" android:duration="150" /> 
  
</animation-list>

res에서 anim 폴더에 simple_animation.xml 입니다.