1. 程式人生 > >android之Animation使用方法二

android之Animation使用方法二

animation的第二種使用方法:

1.在res資料夾中建立一個名為anim的資料夾。

2.在anim資料夾中建立各個動畫的xml檔案

  在xml檔案中首先加入set標籤

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/accelerate_interpolator">

 </set>

3.在該標籤當中加入alpha scal rotate或者translate標籤

4.在程式碼中用AnimationUtils當中裝載xml檔案並生成Animation物件

舉例旋轉動畫標籤:

<rotate android:fromDegrees="0"
  android:toDegrees="360"
  android:pivotX="50%"
  android:pivotY="50%"
  android:duration="5000" />

android:pivotX共有三種設定方式:

android:pivotx="50"這種設定方式是使用絕對位置定位的。