Android動畫 幀動畫

2021-09-22 09:41:39 字數 3831 閱讀 1410

首先在res中新建乙個drawable資料夾,將需要展示的放在裡面,同樣的還有展示的fight.xml檔案,**如下: 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

<?xml version="1.0"encoding="utf-8"?>

android:oneshot="false">

android:drawable="@drawable/fight_1"

android:duration="200"/>

android:drawable="@drawable/fight_2"

android:duration="200"/>

android:drawable="@drawable/fight_3"

android:duration="200"/>

android:drawable="@drawable/fight_4"

android:duration="200"/>

android:drawable="@drawable/fight_5"

android:duration="200"/>

android:drawable="@drawable/fight_6"

android:duration="200"/>

android:drawable="@drawable/fight_7"

android:duration="200"/>

android:drawable="@drawable/fight_8"

android:duration="200"/>

android:drawable="@drawable/fight_9"

android:duration="200"/>

android:drawable="@drawable/fight_10"

android:duration="200"/>

android:drawable="@drawable/fight_11"

android:duration="200"/>

資料夾的布局:

mainactivity定義乙個imageview,

oncreate中呼叫: 1

2

3

imageview fightimage = (imageview) findviewbyid(r.id.image_aniation);

fightimage.setbackgroundresource(r.drawable.fight);

fightnimation = (animationdrawable) fightimage.getbackground();

不能載入的時候立即呼叫,需要在觸控的時候呼叫: 1

2

3

4

5

6

7

publicbooleanontouchevent(motionevent event)

returnsuper.ontouchevent(event);

}

效果如下:

Android動畫之幀動畫詳解

xml資源檔案方式 1.在res drawable目錄中放入需要的 3.在布局檔案中進行設定animationdrawable animationdrawable animationdrawable imageview.getbackground 開始動畫 animationdrawable.sta...

android 動畫1 動畫補間動畫和幀動畫

透明方式 方式 animation alphaanimation new alphaanimation 0.0f,1.0f 載入 動畫資源檔案 animation animation animationutils.loadanimation this,r.anim.alpha anim imagev...

Android補間動畫 逐幀動畫

逐幀動畫 補間動畫補間動畫補間動畫 分為四種 1.透明度變化 2.旋轉 3.平移 4.放大縮小透明度變化 步驟 1.new alphaanimation fromalpha,toalpha 1.fromalpha 透明度的初始值 0.0f 1.0f之間 2.toalpha 結束時的透明度的值 0.0...