Android利用animation-list實(shí)現(xiàn)幀動畫
本文實(shí)例為大家分享了利用animation-list實(shí)現(xiàn)幀動畫的具體代碼,供大家參考,具體內(nèi)容如下
將要順序播放的圖片放在資源目錄下
再drawable目錄下新建animation1文件和animation2文件 一個是按順序顯示動畫,一個是倒序顯示動畫,
順序顯示動畫文件:animation1.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會不停的循環(huán)播放動畫 根標(biāo)簽下,通過item標(biāo)簽對動畫中的每一個圖片進(jìn)行聲明 android:duration 表示展示所用的該圖片的時間長度 --> <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>
倒序顯示動畫文件:animation2.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會不停的循環(huán)播放動畫 根標(biāo)簽下,通過item標(biāo)簽對動畫中的每一個圖片進(jìn)行聲明 android:duration 表示展示所用的該圖片的時間長度 --> <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(); } }); } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 圖像處理(類型轉(zhuǎn)換,比例縮放,倒影,圓角)的小例子
Android 圖像處理(類型轉(zhuǎn)換,比例縮放,倒影,圓角)的小例子,需要的朋友可以參考一下2013-05-05Android開發(fā)歡迎頁點(diǎn)擊跳過倒計(jì)時進(jìn)入主頁
沒點(diǎn)擊跳過自然進(jìn)入主頁,點(diǎn)擊跳過之后立即進(jìn)入主頁,這個功能怎么實(shí)現(xiàn)呢,本文通過實(shí)例代碼給大家介紹Android開發(fā)歡迎頁點(diǎn)擊跳過倒計(jì)時進(jìn)入主頁,感興趣的朋友一起看看吧2023-12-12Android中使用GridView和ImageViewSwitcher實(shí)現(xiàn)電子相冊簡單功能實(shí)例
本篇文章主要介紹了Android中使用GridView和ImageViewSwitcher實(shí)現(xiàn)電子相冊簡單功能實(shí)例,具有一定的參考價(jià)值,有需要的可以了解一下。2016-12-12深入剖析Android系統(tǒng)中Service和IntentService的區(qū)別
這篇文章主要介紹了Android系統(tǒng)中Service和IntentService的區(qū)別,與普通的服務(wù)相比,IntentService可以開啟單獨(dú)的線程來處理intent請求,需要的朋友可以參考下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ù)時間戳的相關(guān)方法總結(jié)
這篇文章主要介紹了Android編程計(jì)算函數(shù)時間戳的相關(guān)方法,結(jié)合實(shí)例形式總結(jié)分析了Android Java、Native、Kernel時間戳計(jì)算相關(guān)操作技巧,需要的朋友可以參考下2017-05-05Android 自定義球型水波紋帶圓弧進(jìn)度效果(實(shí)例代碼)
最近小編接到一個這樣的需求,需要實(shí)現(xiàn)一個圓形水波紋,帶進(jìn)度,兩層水波紋需要漸變顯示,且外圍有一個圓弧進(jìn)度。今天小編給大家分享實(shí)例代碼,感興趣的朋友一起看看吧2019-12-12