Android 애니메이션(볼 드롭)

2205 단어 Android
애니메이션 효과

1. 애니메이션 설정 상수, 시간, 횟수 및 모드
//時間
private final int DURATION_TIME = 2000;
//回数
private final int REPEAT_COUNT = Animation.INFINITE;
//2回以降の開始位置、
//RESTART:初回の開始位置
//REVERSE:終了位置
private final int REPEAT_MODE = Animation.RESTART; //REVERSE RESTART
2. 애니메이션 초기화
//大きさアニメーション
private ScaleAnimation scaleAnimation;
{
    scaleAnimation = new ScaleAnimation(
            1f,0.5f,                                 //Xの開始大きさ
            1f,0.5f,                                 //Yの開始大きさ
            Animation.RELATIVE_TO_SELF,0.5f,       //開始位置の位置X
            Animation.RELATIVE_TO_SELF,0.5f        //開始位置の位置Y
    );
    scaleAnimation.setDuration(DURATION_TIME);
    scaleAnimation.setRepeatCount(REPEAT_COUNT);
    scaleAnimation.setRepeatMode(REPEAT_MODE);
}

//移動アニメーション初期化
private TranslateAnimation translateAnimation;
{
    //Animation.RELATIVE_TO_PARENT  親のViewに対して
    //Animation.RELATIVE_TO_SELF      自分のViewに対して
    translateAnimation = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,0, //"X"開始位置のタイプとValue
            Animation.RELATIVE_TO_PARENT,0f, //"X"終了位置のタイプとValue
            Animation.RELATIVE_TO_PARENT,0, // "Y"開始位置のタイプとValue 
            Animation.RELATIVE_TO_PARENT,0.9f // "Y"終了位置のタイプとValue
    );
    //アニメーションの時間
    translateAnimation.setDuration(DURATION_TIME);
    //アニメーションの回数数字または Animation.INFINITE(無限回)
    translateAnimation.setRepeatCount(REPEAT_COUNT);
    //アニメーションのMode
    translateAnimation.setRepeatMode(REPEAT_MODE);
}
3. 애니메이션 설정
    //ボール跳ね返す効果
    animationSet.setInterpolator(new BounceInterpolator());
    //アニメーション設定
    animationSet.addAnimation(scaleAnimation);
    animationSet.addAnimation(translateAnimation);
4. 애니메이션 시작
    btn_start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            img_ball.startAnimation(animationSet);
        }
    });
소스 코드
잘 자는 거 잊지 마.

좋은 웹페이지 즐겨찾기