天天看點

Android動畫——Tween動畫之Rotate

建立資源檔案

在res檔案夾下建立anim檔案夾,在anim中建立一個資源檔案,檔案名随意

Android動畫——Tween動畫之Rotate

編寫代碼

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="+360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="50"
    android:duration="100"/>
           

屬性介紹

android:fromDegrees 動畫開始時的角度(正負360)
android:toDegress   動畫結束時的角度(正負360)
android:pivotX  旋轉中心點X的位置
android:pivotY  旋轉中心點Y的位置
android:repeatCount 動畫重複次數
android:duration    每次動畫持續時間
           

初始化動畫

imageView = (ImageView) rootView.findViewById(R.id.imageview);
animation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
           

開始動畫

結束動畫