天天看點

Animation 作為ImageView的背景

聲明一個Animation

<!-- 定義動畫循環播放 -->

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

android:oneshot="false">

<item android:drawable="@drawable/butterfly_f01" android:duration="120" />

<item android:drawable="@drawable/butterfly_f02" android:duration="120" />

<item android:drawable="@drawable/butterfly_f03" android:duration="120" />

<item android:drawable="@drawable/butterfly_f04" android:duration="120" />

<item android:drawable="@drawable/butterfly_f05" android:duration="120" />

<item android:drawable="@drawable/butterfly_f06" android:duration="120" /> </animation-list>

2.布局檔案

<ImageView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:background="@anim/butterfly" />

3.開啟動畫

AnimationDrawable animDrawable = imageView.getBackgound();

animDrawable.start();

本文轉自wauoen51CTO部落格,原文連結:http://blog.51cto.com/7183397/1567596 ,如需轉載請自行聯系原作者

繼續閱讀