티스토리 뷰

프로그래밍 언어/android

animation

오치리 2010. 1. 20. 18:49
2. AnimationDrawable
//Drawble객체를 파생하는 이유는 특정하게 그릴수 있는 객체를 하나 만들어서 .Draw(Canvers)를
//콜하면 Canvers 위에 Drawable 객체를 그려준다.
//객체를 한번 생성한후에 그객체를 그냥 Draw함수만 부르면 밑에 드로우 로직이 어떤지는 알 필요 없이
//그려지게 하기 위한 역할을 만들 수 있다.
public class ProxyDrawable extends Drawable {
..기타 함수들을 override를 한다.
//그려질지 말지를 셋팅을 한다.
@Override
public Drawable mutate() {
if (mProxy != null && !mMutated && super.mutate() == this) {
mProxy.mutate();
mMutated = true;
}
return this;
}
}

public class AnimateDrawable extends ProxyDrawable {

private Animation mAnimation;
private Transformation mTransformation = new Transformation();

public AnimateDrawable(Drawable target) {
super(target);
}

public AnimateDrawable(Drawable target, Animation animation) {
super(target);
mAnimation = animation;
}

public Animation getAnimation() {
return mAnimation;
}

public void setAnimation(Animation anim) {
mAnimation = anim;
}

public boolean hasStarted() {
return mAnimation != null && mAnimation.hasStarted();
}

public boolean hasEnded() {
return mAnimation == null || mAnimation.hasEnded();
}

@Override
public void draw(Canvas canvas) {
Drawable dr = getProxy();
if (dr != null) {
//롤백할 캔버스 객체를 저장한다.
int sc = canvas.save();
Animation anim = mAnimation;
if (anim != null) {
//Animation객체를
anim.getTransformation(
AnimationUtils.currentAnimationTimeMillis(),
mTransformation);
//캔퍼스를 이동한다.
canvas.concat(mTransformation.getMatrix());
}
//dr객체를 캔버스에 그려준다.
dr.draw(canvas);
//어디가지 기억한 캔버스로 돌아간다.
canvas.restoreToCount(sc);
}
}
}


private static class SampleView extends View {
private AnimateDrawable mDrawable;

public SampleView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);

Drawable dr = context.getResources().getDrawable(R.drawable.beach);
dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());

Animation an = new TranslateAnimation(0, 100, 0, 200);
an.setDuration(2000);
an.setRepeatCount(-1);
an.initialize(10, 10, 10, 10);

mDrawable = new AnimateDrawable(dr, an);
an.startNow();
}

@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);

mDrawable.draw(canvas);
invalidate();
}
}


'프로그래밍 언어 > android' 카테고리의 다른 글

스피드 랭킹퍼즐  (0) 2024.03.21
sound  (0) 2010.01.28
이미지 읽어오기  (0) 2010.01.20
비트맵 그리기  (0) 2009.10.29
FrameLayout 에서 Thread를 이용한 이미지(또는 애니메이트) 그리기  (0) 2009.10.29
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함