Android中AnimationDrawable使用的簡單實例
更新時間:2013年10月16日 15:53:19 作者:
這篇文章介紹了Android中AnimationDrawable使用的簡單實例,有需要的朋友可以參考一下
首先,可以在drawable文件夾下定義一個xml的文件。如下所示:
復制代碼 代碼如下:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/compass_1" android:duration="70" />
<item android:drawable="@drawable/compass_2" android:duration="70" />
<item android:drawable="@drawable/compass_3" android:duration="70" />
<item android:drawable="@drawable/compass_4" android:duration="70" />
<item android:drawable="@drawable/compass_5" android:duration="70" />
</animation-list>
根標簽為animation-list,其中oneshot代表著是否只展示一遍,設置為false會不停的循環(huán)播放動畫。其中,每一個item是一幀,android:duration="400"表示每幀持續(xù)400ms,android:drawable是每幀要顯示的圖片。
接下來,代碼中使用:
復制代碼 代碼如下:
AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(R.drawable.bootanimation);
得到AnimationDrawable對象。再將該對象設為當前view的backgroud。
復制代碼 代碼如下:
mView.setBackgroundDrawable(ad);
接著,就可以調用 ad.start()方法和ad.stop()方法來啟動和停止該動畫。
注意:必須設為當前view的background,否則start和stop該動畫是沒有效果的。
相關文章
Material Design系列之Behavior實現支付密碼彈窗和商品屬性選擇效果
這篇文章主要為大家詳細介紹了Material Design系列之Behavior實現支付密碼彈窗和商品屬性選擇效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
Android使用Jetpack Compose開發(fā)零基礎起步教程
Jetpack Compose是用于構建原生Android UI的現代工具包。Jetpack Compose使用更少的代碼,強大的工具和直觀的Kotlin API,簡化并加速了Android上的UI開發(fā)2023-04-04
關于Android中WebView遠程代碼執(zhí)行漏洞淺析
這篇文章主要給大家介紹了關于Android中WebView遠程代碼執(zhí)行漏洞的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-05-05

