方法一
用 AnimationUtils 和 xml 的方式,加載指定的縮放動畫。
Animation scaleAnimation = AnimationUtils.loadAnimation(mContext, R.anim.scale_animation);
scaleAnimation.setFillAfter(true);
mImageView.startAnimation(scaleAnimation);
scale_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!--
android:fromXScale
Float. 水準方向縮放比例的初始值,其中1.0是沒有任何變化。
android:toXScale
Float. 水準方向縮放比例的結束值,其中1.0是沒有任何變化。
android:fromYScale
Float. 豎直方向縮放比例的初始值,其中1.0是沒有任何變化。
android:toYScale
Float. 豎直方向縮放比例的結束值,其中1.0是沒有任何變化。
android:pivotX
Float. 縮放中心點的x坐标
android:pivotY
Float. 縮放中心點的y坐标
-->
<scale
android:duration="5000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5" />
</set>
ScaleAnimation scaleAnim = new ScaleAnimation(1, 1.5f, 1,1.5f);
scaleAnim.setFillAfter(true);
mImageView.startAnimation(scaleAnim);
//利用AnimatorSet和ObjectAnimator實作縮放動畫
final AnimatorSet animatorSet = new AnimatorSet();
mImageView.setPivotX(mImageView.getWidth() / 2);
mImageView.setPivotY(mImageView.getHeight() / 2);
animatorSet.playTogether(
ObjectAnimator.ofFloat(mImageView, "scaleX", 1, 1.5f).setDuration(5000),
ObjectAnimator.ofFloat(mImageView, "scaleY", 1, 1.5f).setDuration(5000));
animatorSet.start();