Android編程之簡(jiǎn)單逐幀動(dòng)畫Frame的實(shí)現(xiàn)方法
本文實(shí)例講述了Android編程之簡(jiǎn)單逐幀動(dòng)畫Frame的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
1、逐幀動(dòng)畫
即是通過播放預(yù)先排序好的圖片來實(shí)現(xiàn)動(dòng)態(tài)的畫面,感覺像是放電影。
2、實(shí)現(xiàn)步驟:
① 在工程里面導(dǎo)入要播放的圖片。此簡(jiǎn)單例子中為start_icon1,2,3.
② 在工程res文件目錄下新建一個(gè)anim文件夾,在里面新建一個(gè)start_animation.xml格式文件,此文件用來定義動(dòng)畫播放圖片的順序及每一張圖片顯示停留時(shí)間。
代碼如下:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/start_icon1" android:duration="1000" /> <item android:drawable="@drawable/start_icon2" android:duration="500" /> <item android:drawable="@drawable/start_icon3" android:duration="600" /> </animation-list>
注:此藍(lán)色部分依次顯示的圖片,存放在drawable-mdpi文件下,一般1秒鐘播放24張圖片(幀)就感覺播放流暢了,即duration為40左右,默認(rèn)單位為毫秒。
3、布局文件:
布局文件中添加一ImageView控件,用來播放動(dòng)畫圖片。具體布局如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="開始" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="結(jié)束" /> <ImageView android:id="@+id/image" android:background="@anim/start_animation" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout>
4、代碼部分:
public class TestActivity extends Activity { AnimationDrawable anim; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start_screen); ImageView image = (ImageView) findViewById(R.id.image); // image.setBackgroundResource(R.anim.start_animation); anim = (AnimationDrawable) image.getBackground(); Button start = (Button) findViewById(R.id.button1); Button stop = (Button) findViewById(R.id.button2); start.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { anim.start(); } }); stop.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { anim.stop(); } }); } }
注:第三步中的android:background="@anim/start_animation"和第四步中的 image.setBackgroundResource(R.anim.start_animation);只要選擇一個(gè)就可以,兩個(gè)都寫顯得累贅,主要功能是指定播放的資源圖片。
小結(jié):這種應(yīng)用在實(shí)際應(yīng)用中應(yīng)該不會(huì)用到,對(duì)于初學(xué)著來說,拿著玩下還是蠻有意思的,不僅增強(qiáng)了對(duì)Android學(xué)習(xí)的興趣,同時(shí)也能加深對(duì)制造電影的一些了解
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android動(dòng)畫之逐幀動(dòng)畫(Frame Animation)實(shí)例詳解
- Android 動(dòng)畫(View動(dòng)畫,幀動(dòng)畫,屬性動(dòng)畫)詳細(xì)介紹
- Android逐幀動(dòng)畫實(shí)現(xiàn)代碼
- Android 使用幀動(dòng)畫內(nèi)存溢出解決方案
- Android之仿美團(tuán)加載數(shù)據(jù)幀動(dòng)畫
- Android動(dòng)畫之逐幀動(dòng)畫(Frame Animation)基礎(chǔ)學(xué)習(xí)
- Android幀動(dòng)畫、補(bǔ)間動(dòng)畫、屬性動(dòng)畫用法詳解
- Android 幀動(dòng)畫的實(shí)例詳解
- Android 逐幀動(dòng)畫創(chuàng)建實(shí)例詳解
- Android Studio實(shí)現(xiàn)幀動(dòng)畫
相關(guān)文章
Android利用Chronometer實(shí)現(xiàn)倒計(jì)時(shí)功能
這篇文章主要為大家詳細(xì)介紹了Android利用Chronometer實(shí)現(xiàn)倒計(jì)時(shí)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11詳解Flutter如何繪制曲線,折線圖及波浪動(dòng)效
這篇文章主要為大家介紹線條類圖形的繪制(正弦曲線、折線圖),并且結(jié)合 Animation 實(shí)現(xiàn)了常見的波浪動(dòng)效,感興趣的小伙伴可以了解一下2022-03-03android使用SharedPreferences進(jìn)行數(shù)據(jù)存儲(chǔ)
Android平臺(tái)給我們提供了一個(gè)SharedPreferences類,它是一個(gè)輕量級(jí)的存儲(chǔ)類,特別適合用于保存軟件配置參數(shù)。有興趣的可以了解一下。2017-02-02Android中實(shí)現(xiàn)用命令行同步網(wǎng)絡(luò)時(shí)間
這篇文章主要介紹了Android中實(shí)現(xiàn)用命令行同步網(wǎng)絡(luò)時(shí)間,本文講解使用BusyBox實(shí)現(xiàn)同步網(wǎng)絡(luò)時(shí)間,并給出了詳細(xì)操作步驟,需要的朋友可以參考下2015-07-07Android使用ShareSDK實(shí)現(xiàn)應(yīng)用分享的功能
這篇文章主要為大家詳細(xì)介紹了Android使用ShareSDK實(shí)現(xiàn)應(yīng)用分享的功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05Android音頻錄制MediaRecorder之簡(jiǎn)易的錄音軟件實(shí)現(xiàn)代碼
這篇文章主要介紹了Android音頻錄制MediaRecorder之簡(jiǎn)易的錄音軟件實(shí)現(xiàn)代碼,有需要的朋友可以參考一下2014-01-01