본문 바로가기

개발도구/aOS - 안드로이드 개발

[안드로이드] 서서히 사라지는 효과 내기 - Animation

정의 ---------------------------------------
Animation a = new TranslateAnimation(0.0f,

parent.getWidth() - target.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), 0.0f, 0.0f);

 

//에니메이션 설정

a.setDuration(1000);

a.setStartOffset(300);
a.setRepeatMode(Animation.RESTART);
a.setRepeatCount(Animation.INFINITE);

 

3. 에니메이션별 interpolator 설정

미리 정의된 안드로이드 에니메이션 설정을 얻는다.

a.setInterpolator( AnimationUtils.loadInterpolator( this, android.R.anim.식별자) );

 

- 점점빠르게 : accelerate_interpolator

- 점점 느리게 이동 : decelerate_interpolator

- 위 둘을 동시에 : accelerate_decelerate_interpolator

- 시작위치에서 조금 뒤로 당겼다 이동 : anticipate_interpolator

- 도착위치를 조금 지나쳤다가 도착위치로 이동 : overshoot_interpolator

- 위 둘을 동시에 : anticipate_overshoot_interpolator

- 도착위치에서 튕김 : bounce_interpolator


실코드--------------------------------
서서히 사라지기 - Animation 1)
public void playStart() {
int timer_sec = 0;
int count = 0;
final LinearLayout top_navi = (LinearLayout)findViewById(R.id.top_navi);
final LinearLayout buttom_navi = (LinearLayout)findViewById(R.id.buttom_navi);

Thread animationThread = new Thread(new Runnable() {
public void run() {
try {
AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
animation.setDuration(1000);
top_navi.startAnimation(animation);
} catch (Throwable t) {
}
}
});
animationThread.start();
Thread animationThread1 = new Thread(new Runnable() {
public void run() {
try {
AlphaAnimation animation1 = new AlphaAnimation(1.0f, 0.0f);
animation1.setDuration(1000);
buttom_navi.startAnimation(animation1);
} catch (Throwable t) {
}
top_navi.setVisibility(View.INVISIBLE);    
buttom_navi.setVisibility(View.INVISIBLE);    
}
});
animationThread1.start();
if(top_navi.getVisibility() == View.VISIBLE){
        // top_navi.setVisibility(View.INVISIBLE);            
       // buttom_navi.setVisibility(View.INVISIBLE);
}else if(top_navi.getVisibility() == View.INVISIBLE){
        top_navi.setVisibility(View.VISIBLE);            
        buttom_navi.setVisibility(View.VISIBLE);
}
second = new TimerTask() {

@Override
public void run() {
Log.i("Test", "Timer start");
Update();
}
};
timer = new Timer();
timer.schedule(second, 3000, 4000);
}



참고 메소드
private void progressProcess() {
	mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
	mProgressBar.setProgress(0);
	Thread progressThread = new Thread(new Runnable() {
		public void run() {
			try {
				while (mIsRunning) {
					if (mProgressBar.getProgress() >= 100) {
						mIsRunning = false;
						goMain();
					} else {
						Thread.sleep(200);
						mHandlerProgress.sendMessage(mHandlerProgress.obtainMessage());
					}
				}
			} catch (Throwable t) {
				Logger.write(t);
			}
		}
	});

	mIsRunning = true;
	progressThread.start(); 
private void imageAnimate() {
	mImageView = (ImageView) findViewById(R.id.splash_image);
	Thread animationThread = new Thread(new Runnable() {
		public void run() {
			try {
				AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
				animation.setDuration(2000);
				mImageView.startAnimation(animation);
			} catch (Throwable t) {
				Logger.write(t);
			}
		}
	});
	animationThread.start();
}
}


서서히 사라지기 - Animation 1)

res/anim/alpha.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
  android:interpolator="@android:anim/accelerate_interpolator"
  android:fromAlpha="1.0" 
  android:toAlpha="0.0"
  android:duration="1000">
  
</alpha>


Animation alphaAnim = AnimationUtils.loadAnimation(this, R.anim.alpha);; top_navi.startAnimation(alphaAnim); buttom_navi.startAnimation(alphaAnim);