[Android] Animation

Android 2012. 7. 24. 18:26



FadeIn FadeOut



      Animation fadeIn = new AlphaAnimation(0, 1);

            fadeIn.setInterpolator(new DecelerateInterpolator()); 

            fadeIn.setDuration(2000);


            Animation fadeOut = new AlphaAnimation(1, 0);

            fadeOut.setInterpolator(new AccelerateInterpolator()); 

            fadeOut.setStartOffset(2000);

            fadeOut.setDuration(2000);


//두 애니메이션을 묶어주기 위한 AnimationSet

            AnimationSet animation = new AnimationSet(true);

            animation.addAnimation(fadeOut);

            animation.addAnimation(fadeIn);



// 애니메이션 이벤트 핸들링을 위한 리스너

            animation.setAnimationListener(new AnimationListener() {

                public void onAnimationStart(Animation animation) {}

                public void onAnimationRepeat(Animation animation) {}

                public void onAnimationEnd(Animation animation) {

                }

            });

            

            

            fl.setAnimation(animation);    

//애니메이션 줄 대상에 애니메이션 세팅







이동 애니메이션


   TranslateAnimation moveAnim = new TranslateAnimation(0, 0, 100, 0);

//( x move from, x move to, y move from, y move to)

    moveAnim.setDuration(1000);

    moveAnim.setFillAfter(true);    //애니메이션이 끝난 후, 그 위치에






AnimationSet의 Repeat


Thread + Handler를 사용.

AnimationSet의 setRepeatCount가 듣지를 않던데...?



...

new Thread(){

public void run(){

while(frame != null){

alphaAnim.sendEmptyMessage(0);

SystemClock.sleep(4000);

}

}

}.start();

...




public final Handler alphaAnim = new Handler() {

public void handleMessage(Message msg) {

 

           

    Animation fadeOut = new AlphaAnimation(1, 0.2f);

            fadeOut.setInterpolator(new AccelerateInterpolator()); 

            fadeOut.setStartOffset(2000);

            fadeOut.setDuration(2000);


            Animation fadeIn = new AlphaAnimation(0.2f, 1);

            fadeIn.setInterpolator(new DecelerateInterpolator()); 

            fadeIn.setDuration(2000);


            AnimationSet animation = new AnimationSet(true);

            animation.addAnimation(fadeOut);

            animation.addAnimation(fadeIn);

           

            //animation.setRepeatCount(100);

            //animation.setRepeatMode(Animation.RESTART);

           

            tv.startAnimation(animation);

}

};








Posted by tenn
,