private void iniAnimation(){
// 透明度动画
ObjectAnimator.ofFloat(mAlphaImage, "alpha", 1, 0, 1)
.setDuration(4000)
.start();
// 缩放
final AnimatorSet animatorSet = new AnimatorSet();
mScaleImage.setPivotX(mScaleImage.getWidth()+250);
mScaleImage.setPivotY(mScaleImage.getHeight()+250);
animatorSet.playTogether(
ObjectAnimator.ofFloat(mScaleImage, "scaleX", 1, 0)
.setDuration(2000),
ObjectAnimator.ofFloat(mScaleImage, "scaleY", 1, 0)
.setDuration(2000)
);
animatorSet.start();
// 平移 translation
final AnimatorSet translationAnimatorSet = new AnimatorSet();
translationAnimatorSet.playTogether(
ObjectAnimator.ofFloat(mTranslationImage, "translationX", 20, 100)
.setDuration(2000),
ObjectAnimator.ofFloat(mTranslationImage, "translationY", 20,100)
.setDuration(2000)
);
translationAnimatorSet.start();
// 利用 ObjectAnimator 实现旋转动画
final AnimatorSet rotateAnimationSet = new AnimatorSet();
rotateAnimationSet.playTogether(
ObjectAnimator.ofFloat(mRotationImage, "rotation",0, 360)
.setDuration(2000)
);
rotateAnimationSet.start();
}
例子:
private void showLessImage() {
// 缩放
final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(layout_clear, "scaleX", 1, 0)
.setDuration(1000),
ObjectAnimator.ofFloat(layout_clear, "scaleY", 1, 0)
.setDuration(1000)
);
animatorSet.start();
}
private void showClearImage(ImageView image) {
image.setVisibility(View.VISIBLE);
// 透明度动画
ObjectAnimator.ofFloat(image, "alpha", 0, 0, 1)
.setDuration(1000)
.start();
}
private void showGoneImage(View view) {
view.setVisibility(View.VISIBLE);
// 透明度动画
ObjectAnimator.ofFloat(view, "alpha", 1, 0, 0)
.setDuration(1000)
.start();
}
private void showViewToCenter(View view) {
// 平移 translation
final AnimatorSet translationAnimatorSet = new AnimatorSet();
translationAnimatorSet.playTogether(
// ObjectAnimator.ofFloat(view, "translationX", view.getX(), new WindowManagerUtils().getScreenHigh(this,"x")/2)
// .setDuration(1000),
// ObjectAnimator.ofFloat(view, "translationY", 100, new WindowManagerUtils().getScreenHigh(this,"y")/2)
ObjectAnimator.ofFloat(view, "translationY", 0, -new WindowManagerUtils().getScreenHigh(this, "y") / 2 + 100)
.setDuration(1000)
);
translationAnimatorSet.start();
}