따라서 사용되는 방법이 프레임 애니메이션입니다.
아래 소스는 프레임 애니메이션은 아니고 배열을 불러와서 루프돌리는 방식의 소스입니다~
package kr.nd.ani;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class AniTest 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.d1);
frame[1] = (BitmapDrawable)getResources().getDrawable(R.drawable.d2);
frame[2] = (BitmapDrawable)getResources().getDrawable(R.drawable.d3);
frame[3] = (BitmapDrawable)getResources().getDrawable(R.drawable.d4);
frame[4] = (BitmapDrawable)getResources().getDrawable(R.drawable.d5);
frame[5] = (BitmapDrawable)getResources().getDrawable(R.drawable.d6);
frame[6] = (BitmapDrawable)getResources().getDrawable(R.drawable.d7);
frame[7] = (BitmapDrawable)getResources().getDrawable(R.drawable.d8);
frame[8] = (BitmapDrawable)getResources().getDrawable(R.drawable.d9);
frame[9] = (BitmapDrawable)getResources().getDrawable(R.drawable.d10);
for(int x = 0; x < 10; x++)
{
ani.addFrame(frame[x],100);
}
ani.setOneShot(false);
return ani;
}
}
//소스 출처 : http://blog.naver.com/PostView.nhn?blogId=read552&logNo=50103459617&viewDate=¤tPage=1&listtype=0
많은 분들 이용하시길 바래요 ~ !