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);
}
});
소스 코드잘 자는 거 잊지 마.
Reference
이 문제에 관하여(Android 애니메이션(볼 드롭)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/YanHengGo/items/6b883fd57583257ba859텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)