LoginSignup
3
6

More than 5 years have passed since last update.

Androidのアニメーション(組み合わせ)

Posted at

ezgif.com-video-to-gif.gif

アニメーションの初期化
1、

//移動アニメーション初期化
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,0.3f, //"X"終了位置のタイプとValue
            Animation.RELATIVE_TO_PARENT,0, // "Y"開始位置のタイプとValue 
            Animation.RELATIVE_TO_PARENT,0.3f // "Y"終了位置のタイプとValue
    );
    //アニメーションの時間
    translateAnimation.setDuration(500);
    //アニメーションの回数数字または Animation.INFINITE(無限回)
    //translateAnimation.setRepeatCount(Animation.INFINITE);
    translateAnimation.setRepeatCount(3);
    //アニメーション停止したら最後の位置に停止する
    translateAnimation.setFillAfter(true);
    //アニメーションのMode
    translateAnimation.setRepeatMode(Animation.REVERSE);
}
private RotateAnimation rotateAnimation;
{
    rotateAnimation = new RotateAnimation(
            0,360,                  //開始と終了度数
            Animation.RELATIVE_TO_SELF,0.5f, //回転の中心作業X
            Animation.RELATIVE_TO_SELF ,0.5f //回転の中心作業Y
    );
    //回転回数
    rotateAnimation.setRepeatCount(3);
    //回転時間
    rotateAnimation.setDuration(500);
}
//消えるアニメーション初期化
private AlphaAnimation alphaAnimation;
{
    alphaAnimation = new AlphaAnimation(
            1,
            0
    );
    alphaAnimation.setDuration(500);
    //消えた後表示しない
    //alphaAnimation.setFillAfter(true);
    //消えた後再表示
    //alphaAnimation.setFillAfter(false);
    alphaAnimation.setRepeatMode(Animation.REVERSE);
    alphaAnimation.setRepeatCount(3);
}
//大きさアニメーション
private ScaleAnimation scaleAnimation;
{
    scaleAnimation = new ScaleAnimation(
            1f,3.0f,                                 //Xの開始大きさ
            1f,3.0f,                                 //Yの開始大きさ
            Animation.RELATIVE_TO_SELF,0.5f,       //開始位置の位置X
            Animation.RELATIVE_TO_SELF,0.5f        //開始位置の位置Y
    );
    scaleAnimation.setDuration(500);
    scaleAnimation.setRepeatCount(3);
    scaleAnimation.setRepeatMode(Animation.REVERSE);
}

2、animationsetの初期化、animationsetにアニメーション追加複数もOK

    animationSet2 = new AnimationSet(false);
    animationSet2.addAnimation(rotateAnimation);
    animationSet2.addAnimation(translateAnimation);

3、animationset完了リスナーの追加完了後に次のアニメーション開始する。

    animationSet2.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            L.d("animationSet2 完了");
            imageView3.startAnimation(animationSet3);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

ソースコード

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6