Android利用animation-list實(shí)現(xiàn)幀動(dòng)畫
本文實(shí)例為大家分享了利用animation-list實(shí)現(xiàn)幀動(dòng)畫的具體代碼,供大家參考,具體內(nèi)容如下
將要順序播放的圖片放在資源目錄下
再drawable目錄下新建animation1文件和animation2文件 一個(gè)是按順序顯示動(dòng)畫,一個(gè)是倒序顯示動(dòng)畫,
順序顯示動(dòng)畫文件:animation1.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會(huì)不停的循環(huán)播放動(dòng)畫 根標(biāo)簽下,通過item標(biāo)簽對(duì)動(dòng)畫中的每一個(gè)圖片進(jìn)行聲明 android:duration 表示展示所用的該圖片的時(shí)間長(zhǎng)度 --> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" > <item android:drawable="@drawable/icon1" android:duration="150"></item> <item android:drawable="@drawable/icon2" android:duration="150"></item> <item android:drawable="@drawable/icon3" android:duration="150"></item> <item android:drawable="@drawable/icon4" android:duration="150"></item> <item android:drawable="@drawable/icon5" android:duration="150"></item> <item android:drawable="@drawable/icon6" android:duration="150"></item> </animation-list>
倒序顯示動(dòng)畫文件:animation2.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會(huì)不停的循環(huán)播放動(dòng)畫 根標(biāo)簽下,通過item標(biāo)簽對(duì)動(dòng)畫中的每一個(gè)圖片進(jìn)行聲明 android:duration 表示展示所用的該圖片的時(shí)間長(zhǎng)度 --> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" > <item android:drawable="@drawable/icon6" android:duration="150"></item> <item android:drawable="@drawable/icon5" android:duration="150"></item> <item android:drawable="@drawable/icon4" android:duration="150"></item> <item android:drawable="@drawable/icon3" android:duration="150"></item> <item android:drawable="@drawable/icon2" android:duration="150"></item> <item android:drawable="@drawable/icon1" android:duration="150"></item> </animation-list>
布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/animationIV" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5px" android:src="@drawable/animation1"/> <Button android:id="@+id/buttonA" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5px" android:text="順序顯示" /> <Button android:id="@+id/buttonB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5px" android:text="停止" /> <Button android:id="@+id/buttonC" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5px" android:text="倒序顯示" /> </LinearLayout>
Activity文件
package org.shuxiang.test; import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.ImageView; public class Activity10 extends Activity { private ImageView animationIV; private Button buttonA, buttonB, buttonC; private AnimationDrawable animationDrawable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.test10); animationIV = (ImageView) findViewById(R.id.animationIV); buttonA = (Button) findViewById(R.id.buttonA); buttonB = (Button) findViewById(R.id.buttonB); buttonC = (Button) findViewById(R.id.buttonC); buttonA.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub animationIV.setImageResource(R.drawable.animation1); animationDrawable = (AnimationDrawable) animationIV.getDrawable(); animationDrawable.start(); } }); buttonB.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub animationDrawable = (AnimationDrawable) animationIV.getDrawable(); animationDrawable.stop(); } }); buttonC.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub animationIV.setImageResource(R.drawable.animation2); animationDrawable = (AnimationDrawable) animationIV.getDrawable(); animationDrawable.start(); } }); } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android結(jié)合xml實(shí)現(xiàn)幀動(dòng)畫
- Android動(dòng)畫系列之幀動(dòng)畫和補(bǔ)間動(dòng)畫的示例代碼
- Android 幀動(dòng)畫的實(shí)例詳解
- Android 逐幀動(dòng)畫創(chuàng)建實(shí)例詳解
- Android之仿美團(tuán)加載數(shù)據(jù)幀動(dòng)畫
- Android逐幀動(dòng)畫實(shí)現(xiàn)代碼
- android 幀動(dòng)畫,補(bǔ)間動(dòng)畫,屬性動(dòng)畫的簡(jiǎn)單總結(jié)
- Android 使用幀動(dòng)畫內(nèi)存溢出解決方案
- Android幀動(dòng)畫、補(bǔ)間動(dòng)畫、屬性動(dòng)畫用法詳解
- Android 幀動(dòng)畫使用詳情
相關(guān)文章
Android 圖像處理(類型轉(zhuǎn)換,比例縮放,倒影,圓角)的小例子
Android 圖像處理(類型轉(zhuǎn)換,比例縮放,倒影,圓角)的小例子,需要的朋友可以參考一下2013-05-05Android開發(fā)歡迎頁(yè)點(diǎn)擊跳過倒計(jì)時(shí)進(jìn)入主頁(yè)
沒點(diǎn)擊跳過自然進(jìn)入主頁(yè),點(diǎn)擊跳過之后立即進(jìn)入主頁(yè),這個(gè)功能怎么實(shí)現(xiàn)呢,本文通過實(shí)例代碼給大家介紹Android開發(fā)歡迎頁(yè)點(diǎn)擊跳過倒計(jì)時(shí)進(jìn)入主頁(yè),感興趣的朋友一起看看吧2023-12-12Android中使用GridView和ImageViewSwitcher實(shí)現(xiàn)電子相冊(cè)簡(jiǎn)單功能實(shí)例
本篇文章主要介紹了Android中使用GridView和ImageViewSwitcher實(shí)現(xiàn)電子相冊(cè)簡(jiǎn)單功能實(shí)例,具有一定的參考價(jià)值,有需要的可以了解一下。2016-12-12深入剖析Android系統(tǒng)中Service和IntentService的區(qū)別
這篇文章主要介紹了Android系統(tǒng)中Service和IntentService的區(qū)別,與普通的服務(wù)相比,IntentService可以開啟單獨(dú)的線程來處理intent請(qǐng)求,需要的朋友可以參考下2016-04-04在Android系統(tǒng)中使用gzip進(jìn)行數(shù)據(jù)傳遞實(shí)例代碼
HTTP協(xié)議上的GZIP編碼是一種用來改進(jìn)WEB應(yīng)用程序性能的技術(shù),4.4MB的文本數(shù)據(jù)經(jīng)過Gzip傳輸?shù)娇蛻舳酥笞優(yōu)?92KB,壓縮效率極高,下面與大家分享下具體的實(shí)現(xiàn)2013-06-06Android 媒體開發(fā)之MediaPlayer狀態(tài)機(jī)接口方法實(shí)例解析
這篇文章主要介紹了Android 媒體開發(fā)之MediaPlayer狀態(tài)機(jī)接口方法實(shí)例解析,需要的朋友可以參考下2017-08-08Android編程計(jì)算函數(shù)時(shí)間戳的相關(guān)方法總結(jié)
這篇文章主要介紹了Android編程計(jì)算函數(shù)時(shí)間戳的相關(guān)方法,結(jié)合實(shí)例形式總結(jié)分析了Android Java、Native、Kernel時(shí)間戳計(jì)算相關(guān)操作技巧,需要的朋友可以參考下2017-05-05Android 自定義球型水波紋帶圓弧進(jìn)度效果(實(shí)例代碼)
最近小編接到一個(gè)這樣的需求,需要實(shí)現(xiàn)一個(gè)圓形水波紋,帶進(jìn)度,兩層水波紋需要漸變顯示,且外圍有一個(gè)圓弧進(jìn)度。今天小編給大家分享實(shí)例代碼,感興趣的朋友一起看看吧2019-12-12