国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android中AnimationDrawable使用的簡單實例

2020-04-11 12:02:16
字體:
供稿:網(wǎng)友

首先,可以在drawable文件夾下定義一個xml的文件。如下所示:

復(fù)制代碼 代碼如下:

<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>

根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會不停的循環(huán)播放動畫。其中,每一個item是一幀,android:duration="400"表示每幀持續(xù)400ms,android:drawable是每幀要顯示的圖片。
接下來,代碼中使用:

復(fù)制代碼 代碼如下:

AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(R.drawable.bootanimation);

得到AnimationDrawable對象。再將該對象設(shè)為當(dāng)前view的backgroud。

復(fù)制代碼 代碼如下:

mView.setBackgroundDrawable(ad);

接著,就可以調(diào)用 ad.start()方法和ad.stop()方法來啟動和停止該動畫。
注意:必須設(shè)為當(dāng)前view的background,否則start和stop該動畫是沒有效果的。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 葫芦岛市| 凤台县| 崇义县| 乐业县| 江口县| 墨竹工卡县| 中山市| 建瓯市| 余庆县| 共和县| 北京市| 上犹县| 壤塘县| 南溪县| 筠连县| 科尔| 龙南县| 东辽县| 略阳县| 岳阳县| 镇巴县| 昌图县| 望都县| 东乌珠穆沁旗| 沂南县| 双流县| 峨眉山市| 达孜县| 牟定县| 荔浦县| 唐河县| 北宁市| 高平市| 叶城县| 册亨县| 临汾市| 鄢陵县| 明溪县| 托克托县| 高州市| 衡东县|