目的
Androidアプリでアニメーションを実装するときのメモ
相変わらず、実装方法がいくつかあり、
webサイトによっては錯綜していたり、バージョンのため実装できなくなったりとかがある感じ。
実装方法
以下コマンドで実装しました。
例としてImageView
を上下にアニメーションさせています。
ImageView image = view.findViewById(R.id.XXX);
//translationYは縦移動。translationXも可能
//scaleXとかもあり大きさの変更などもできる。
ObjectAnimator animator1 = ObjectAnimator.ofFloat(image, "translationY", 0.0f, -188.0f );
ObjectAnimator animator2 = ObjectAnimator.ofFloat(image, "translationY", -188.0f, 0.0f );
AnimatorSet set = new AnimatorSet();
//アニメーション実行回数
animator1.setRepeatCount(10);
//アニメーション逆再生
animator1.setRepeatMode(ValueAnimator.REVERSE);
//実行時間
set.setDuration(1500);
//playSequentiallyは順番にアニメーション実行animator1->animator2
//playTogetherは同時に実行
set.playSequentially(animator1, animator2);
set.start();
以上です。