Android Animation 之 Drawable Animation(幀動畫)

一、簡介

       幀動畫是一個接一個地加載一系列Drawable資源來創建一個動畫。這是一種傳統的動畫,它是利用一系列不同的圖像按順序播放來實現一個動畫,就像一卷膠捲。

二、詳解

1.常用屬性介紹

  animationDrawable.start();//動畫開始。
  animationDrawable.setOneShot(true);//設置動畫是否只播放一次。
  animationDrawable.stop();//動畫停止。
  animationDrawable.isRunning();//返回動畫是否正在運行。
  animationDrawable.addFrame(getResources().getDrawable(R.drawable.explode_1), 80);//通過代碼添加幀

三、示例

1.Java代碼實現

  imageView1 = (ImageView) findViewById(R.id.imageView1);
  imageView1.setBackgroundResource(R.drawable.explode_anim);
  AnimationDrawable animationDrawable = (AnimationDrawable) imageView1.getBackground();
  animationDrawable.start();

2.XML實現

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item
        android:drawable="@drawable/explode_1"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_2"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_3"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_4"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_5"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_6"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_7"
        android:duration="80"></item>
</animation-list>

3.示例效果

4.示例代碼下載地址

      github地址 https://github.com/Ya-Jun/SmallSampleCollection

四、文檔

      文檔本地查看路徑

      file:///D:/Android/android-sdk-windows/docs/guide/topics/graphics/drawable-animation.html

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