Android動畫——Tween動畫之Rotate

創建資源文件

在res文件夾下創建anim文件夾,在anim中新建一個資源文件,文件名隨意
這裏寫圖片描述

編寫代碼

<?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);

開始動畫

imageView.startAnimation(animation);

結束動畫

animation.cancel();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章