그냥 간단하게 프레임 애니메이션을 구현하는예제인데요....
제가 public AnimationDrawable getAnimation() 이라는 함수를 만들었는데..
그 함수의 기능은 이름그대로.. 프레임,oneShot을 설정해주고 그것을 반환해주는 함수입니다.
그 함수를 호출한곳에서는 그 값을 가지고 start()만 하면 애니메이션이 동작되는건데요..
이게 동일 한 클래스에 있을때는 아무런 문제없이 잘~~ 동작하는데..
클래스를 나누어 버리니깐..
에뮬레이터 실행시에 바로 종료가 되더라구요..
그냥 저 함수를 클래스 하나 만들어서 복사 붙여넣기 했을뿐인데... 왜 그런지 모르겠네요... ㅠㅠ
초보좀 도와주세요~~
우선 아래는 소스 첨부할게요~..
첫번째 소스는 하나의 클래스 안에서 동작하는거구요.. 정상적으로..
두번째 소스는 클래스를 분할 한거에요..
==============첫번째 소스==================== package pmj.aniTest22;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.widget.ImageView;
public class aniTest22 extends Activity {
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }
public void onWindowFocusChanged (boolean hasFocus) { ImageView img = (ImageView)findViewById(R.id.imgv); AnimationDrawable ani; ani = getAnimation();//애니메이션을 불러옵니다. img.setBackgroundDrawable(ani); ani.start();//정상적으로 애니메이션이 구현되는예제.. } public AnimationDrawable getAnimation() { AnimationDrawable ani = new AnimationDrawable(); BitmapDrawable[] frame = new BitmapDrawable[10]; frame[0] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom00); frame[1] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom01); frame[2] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom02); frame[3] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom03); frame[4] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom04); frame[5] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom05); frame[6] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom06); frame[7] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom07); frame[8] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom08); frame[9] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom09); for(int x = 0; x < 10; x++) { ani.addFrame(frame[x],100); } ani.setOneShot(false); return ani; } } |
==============두번째 소스====================
메인에 해당하는 클래스입니다. package pmj.aniTest22;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.widget.ImageView;
public class aniTest22 extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }
public void onWindowFocusChanged (boolean hasFocus) { ImageView img = (ImageView)findViewById(R.id.imgv); getAni aa = new getAni(); AnimationDrawable ani; ani = aa.getAnimation(); img.setBackgroundDrawable(ani); ani.start(); } } |
|
이것은 새로 생성한 getAni라는 클래스 입니다. |
package pmj.aniTest22; import pmj.aniTest22.R; import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable;
public class getAni extends Activity{
public AnimationDrawable getAnimation() { AnimationDrawable ani = new AnimationDrawable(); BitmapDrawable[] frame = new BitmapDrawable[10]; frame[0] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom00); frame[1] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom01); frame[2] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom02); frame[3] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom03); frame[4] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom04); frame[5] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom05); frame[6] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom06); frame[7] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom07); frame[8] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom08); frame[9] = (BitmapDrawable)getResources().getDrawable(R.drawable.boom09); for(int x = 0; x < 10; x++) { ani.addFrame(frame[x],100); } ani.setOneShot(false); return ani; } }
|