LoginSignup
1
0

More than 5 years have passed since last update.

Androidのアニメーション(画像1つ)

Last updated at Posted at 2018-10-11

アニメーション効果
アニメーション.gif

1、移動アニメーション

    //回転アニメーションのテスト
    Button button_translation = (Button)findViewById(R.id.button_translation);
    button_translation.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Animation.RELATIVE_TO_PARENT  親のViewに対して
            //Animation.RELATIVE_TO_SELF      自分のViewに対して
            TranslateAnimation 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(2000);
            //アニメーションの回数数字または Animation.INFINITE(無限回)
            //translateAnimation.setRepeatCount(Animation.INFINITE);
            translateAnimation.setRepeatCount(4);
            //アニメーション停止したら最後の位置に停止する
            translateAnimation.setFillAfter(true);
            //アニメーションのMode
            translateAnimation.setRepeatMode(Animation.REVERSE);
            //imageViewにアニメーションの開始
            imageView.startAnimation(translateAnimation);
        }
    });

2、回転アニメーション

    //回転アニメーションテスト
    Button button_rotate = (Button)findViewById(R.id.button_rotate);
    button_rotate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            L.d();
            RotateAnimation rotateAnimation = new RotateAnimation(
                    0,360,                  //開始と終了度数
                    Animation.RELATIVE_TO_SELF,0.5f, //回転の中心作業X
                    Animation.RELATIVE_TO_SELF ,0.5f //回転の中心作業Y
            );
            //回転回数
            rotateAnimation.setRepeatCount(5);
            //回転時間
            rotateAnimation.setDuration(1000);
            //回転開始
            imageView.startAnimation(rotateAnimation);
        }
    });

3、消えるアニメーション

    //消えるアニメーションテスト
    Button button_alpha = (Button)findViewById(R.id.button_alpha);
    button_alpha.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            L.d();
            AlphaAnimation alphaAnimation = new AlphaAnimation(
                    1,
                    0
            );
            alphaAnimation.setDuration(2000);
            //消えた後表示しない
            //alphaAnimation.setFillAfter(true);
            //消えた後再表示
            //alphaAnimation.setFillAfter(false);
            alphaAnimation.setRepeatMode(Animation.REVERSE);
            alphaAnimation.setRepeatCount(5);
            imageView.startAnimation(alphaAnimation);
        }
    });

4、大きさアニメーション

    //大きさアニメーションテスト
    Button button_scale = (Button)findViewById(R.id.button_scale);
    button_scale.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            L.d();
            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(2000);
            scaleAnimation.setRepeatCount(5);
            scaleAnimation.setRepeatMode(Animation.REVERSE);
            imageView.startAnimation(scaleAnimation);

        }
    });

ソースコード

1
0
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
1
0