創建資源文件
在res文件夾下創建anim文件夾,在anim中新建一個資源文件,文件名隨意
編寫代碼
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0"
android:toXScale="2.0"
android:fromYScale="1.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="3000"
android:repeatCount="10"/>
屬性介紹
android:fromXScale 動畫開始時X軸倍數
android:toXScale 動畫結束時X軸倍數
android:fromYScale 動畫開始時Y軸倍數
android:toYScale 動畫結束時Y軸倍數
android:pivotX 縮放中心點的X軸位置
android:pivotY 縮放中心點的Y軸位置
android:fillAfter 動畫結束後停在最後一幀
android:duration 每次動畫持續時間
android:repeatCount 動畫重複次數
初始化動畫
imageView = (ImageView) rootView.findViewById(R.id.imageview);
animation = AnimationUtils.loadAnimation(getContext(), R.anim.scale);
開始動畫
imageView.startAnimation(animation);
結束動畫
animation.cancel();