2011년 3월 10일 목요일

Android animation sample

public class AnimationTest extends Activity {
/** Called when the activity is first created. */

private AnimationDrawable aniDraw;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

BitmapDrawable ani1 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani1);
BitmapDrawable ani2 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani2);
BitmapDrawable ani3 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani3);
BitmapDrawable ani4 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani4);
BitmapDrawable ani5 = (BitmapDrawable)getResources().getDrawable(R.drawable.ani5);

aniDraw = new AnimationDrawable();
aniDraw.addFrame(ani1,100);
aniDraw.addFrame(ani2,100);
aniDraw.addFrame(ani3,100);
aniDraw.addFrame(ani4,100);
aniDraw.addFrame(ani5,100);

ImageView imgView = (ImageView)findViewById(R.id.imgView);

imgView.setBackgroundDrawable(aniDraw);
aniDraw.setOneShot(false);

Button btn = (Button)findViewById(R.id.btn);

btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
aniDraw.start();
}

});



}
}

댓글 없음:

댓글 쓰기