public class test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button onButton = (Button) findViewById(R.id.Button01);
onButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startAnimation();
}
});
// Handle Stop Button
final Button offButton = (Button) findViewById(R.id.Button02);
offButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stopAnimation();
}
});
}
AnimationDrawable mframeAnimation = new AnimationDrawable();
private void startAnimation()
{
ImageView img = (ImageView)findViewById(R.id.CharacterView);
BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.chick03_1);
BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.chick03_2);
BitmapDrawable frame3 = (BitmapDrawable)getResources().getDrawable(R.drawable.chick03_3);
// Get the background, which has been compiled to an AnimationDrawable object.
int reasonableDuration = 250;
mframeAnimation.setOneShot(false); // loop continuously
mframeAnimation.addFrame(frame1, reasonableDuration);
mframeAnimation.addFrame(frame2, reasonableDuration);
mframeAnimation.addFrame(frame3, reasonableDuration);
img.setBackgroundDrawable(mframeAnimation);
mframeAnimation.setVisible(true,true);
mframeAnimation.start();
}
private void stopAnimation()
{
mframeAnimation.stop();
mframeAnimation.setVisible(false,false);
}
}
처럼 해서 버튼을 클릭하면 애니매이션이 잘 실행되는데요~
어플 실행되자마자 움직이도록 하기 위해서
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startAnimation();
}
이렇게 해두면 되지 않내요 -ㅅ- 클릭해서 실행되나 처음에 어플 실행될때 실행되나 같아야 되는거 아닌가요?;;
변수 생성을 Class 앞부분에서 (onCreate() 전에) 하고
onCreate()에서 각 변수에 값을 넣어준 후 onStart()에서
애니메이션을 start()시키면 될라나요.... 흠...




화면이 나오는 시점이 onCreate안에서 수행하는 내용을 다 처리하고
화면이 나오더군요... 왠지 화면이 보여지기 전에 이미 돌아가고
다 돌아간 화면이 나오는것 같습니다...