Android之Animations的使用

2021-07-10 04:35:21 字數 1733 閱讀 8746

animations一般分為兩大類,一類是漸變的(tweened):如淡入淡出,旋轉,移動,縮放;另一類是frame-by-frame,就如電影一般由多張按照一定的時間間隔顯示。

使用tweened animations的第一種使用步驟:

1. 建立乙個animationset物件,animationset animationset = new animationset (boolean b);   //b為true表示共享interpolator

2. 根據需要建立相應的animation物件(alphaanimation、rotateanimation、scaleanimation、translateanimation)

3. 根據軟體動畫的需求,為animation物件設定相應的資料

4. 將animation物件新增到animationset物件當中,使用addanimation方法

5. 使用控制項物件開始執行animationset 

使用tweened animations的第二種使用步驟: 

1.  在res資料夾下面新建乙個名為anim的資料夾

2. 建立xml檔案,並首先加入set標籤,改標籤如下:

android:interpolator="@android:anim/accelerate_interpolator"> //interpolator定義動畫變化的速率

3. 在該標籤當中加入rotate,alpha,scale或者translate標籤,例子如下:

android:fromalpha = "0.1"

android:toalpha = "1.0"

android:duration = "3000"/> 

android:fromdegrees="0"

android:todegrees="+350"

android:pivotx="50%"

android:pivoty="50%"

android:duration="3000"/>

---注意---android:pivotx的值共有三種設定方法:

1. android:pivotx="50"這種方法使用絕對位置定位

2. android:pivotx="50%"這種方法相對於控制項本身定位

3. android:pivotx="50%p"這種方法相對於控制項的父控制項定位 

4. 在**當中使用animationutils當中裝載xml檔案,並生成animation物件,animationutils.loadanimation

frame-by-frame:使用方法

1. 在res/drawable當中建立乙個xml檔案,用於定義animations的動畫序列,以下是例子:

xmlns:android=""

android:oneshot="false">

android:duration="500"/> 

android:duration="500"/> 

android:duration="500"/>  

android:duration="500"/>  

2. imageview. setbackgroundresource("在res/drawable當中建立乙個xml檔案的id");

3. animationdrawable animationdrawable = (animationdrawable)imageview.getbackground();

4. animationdrawable.start(); 

作業中關於H5中動畫的實現 animation

h5 動畫名 animation name page1 scale 動畫時間 為2s animation duration 2s 動畫次數 數字代表的就是次數 infinite無限迴圈 animation iteration count infinite 動畫效果 animation timing ...

android之interpolator的用法詳解

acceleratedecelerateinterpolator 在動畫開始與結束的地方速率改變比較慢,在中間的時候加速 accelerateinterpolator 在動畫開始的地方速率改變比較慢,然後開始加速 anticipateinterpolator 開始的時候向後然後向前甩 anticip...

android之interpolator的用法詳解

android interpolator,經常和scorllercompat 配合使用,scrollercompat 是乙個控制滑動的類 interpolator 也可以通過 animation 的 setinterpolator 進行設定 interpolator 被用來修飾動畫效果,定義動畫的變...