久しぶりにAndroidアプリでアニメーションしています。
説明はあとで書きます。
アニメーションさせる
imageView
のアルファ値を1秒(1,000ミリ秒)かけて0(透明)するアニメーションです。
ObjectAnimator.ofFloat(imageView, "alpha", 0).setDuration(1000).start();
任意のInterpolatorを指定したObjectAnimatorを得る
private ObjectAnimator makeObjectAnimator(final View view, final String property, final float value, final TimeInterpolator interpolator) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, property, value).setDuration(1000); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { animation.setInterpolator(interpolator); } }); return animator; }
LinearInterpolatorクラスを使う場合です。
makeObjectAnimator(imageView, "alpha", 0, new LinearInterpolator());
複数のアニメーションを同時に実行する
4倍に拡大します。
final List<Animator> animators = new ArrayList<>(); animators.add(makeObjectAnimator(imageView, "scaleX", 4.0f, new LinearInterpolator())); animators.add(makeObjectAnimator(imageView, "scaleY", 4.0f, new LinearInterpolator())); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(animators); return animatorSet;