Android編程之簡單逐幀動畫Frame的實(shí)現(xiàn)方法
本文實(shí)例講述了Android編程之簡單逐幀動畫Frame的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
1、逐幀動畫
即是通過播放預(yù)先排序好的圖片來實(shí)現(xiàn)動態(tài)的畫面,感覺像是放電影。
2、實(shí)現(xiàn)步驟:
① 在工程里面導(dǎo)入要播放的圖片。此簡單例子中為start_icon1,2,3.
② 在工程res文件目錄下新建一個anim文件夾,在里面新建一個start_animation.xml格式文件,此文件用來定義動畫播放圖片的順序及每一張圖片顯示停留時間。
代碼如下:
<?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控件,用來播放動畫圖片。具體布局如下:
<?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);只要選擇一個就可以,兩個都寫顯得累贅,主要功能是指定播放的資源圖片。
小結(jié):這種應(yīng)用在實(shí)際應(yīng)用中應(yīng)該不會用到,對于初學(xué)著來說,拿著玩下還是蠻有意思的,不僅增強(qiáng)了對Android學(xué)習(xí)的興趣,同時也能加深對制造電影的一些了解
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android動畫之逐幀動畫(Frame Animation)實(shí)例詳解
- Android 動畫(View動畫,幀動畫,屬性動畫)詳細(xì)介紹
- Android逐幀動畫實(shí)現(xiàn)代碼
- Android 使用幀動畫內(nèi)存溢出解決方案
- Android之仿美團(tuán)加載數(shù)據(jù)幀動畫
- Android動畫之逐幀動畫(Frame Animation)基礎(chǔ)學(xué)習(xí)
- Android幀動畫、補(bǔ)間動畫、屬性動畫用法詳解
- Android 幀動畫的實(shí)例詳解
- Android 逐幀動畫創(chuàng)建實(shí)例詳解
- Android Studio實(shí)現(xiàn)幀動畫
相關(guān)文章
Android利用Chronometer實(shí)現(xiàn)倒計時功能
這篇文章主要為大家詳細(xì)介紹了Android利用Chronometer實(shí)現(xiàn)倒計時功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11android使用SharedPreferences進(jìn)行數(shù)據(jù)存儲
Android平臺給我們提供了一個SharedPreferences類,它是一個輕量級的存儲類,特別適合用于保存軟件配置參數(shù)。有興趣的可以了解一下。2017-02-02Android中實(shí)現(xiàn)用命令行同步網(wǎng)絡(luò)時間
這篇文章主要介紹了Android中實(shí)現(xiàn)用命令行同步網(wǎng)絡(luò)時間,本文講解使用BusyBox實(shí)現(xiàn)同步網(wǎng)絡(luò)時間,并給出了詳細(xì)操作步驟,需要的朋友可以參考下2015-07-07Android使用ShareSDK實(shí)現(xiàn)應(yīng)用分享的功能
這篇文章主要為大家詳細(xì)介紹了Android使用ShareSDK實(shí)現(xiàn)應(yīng)用分享的功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05Android音頻錄制MediaRecorder之簡易的錄音軟件實(shí)現(xiàn)代碼
這篇文章主要介紹了Android音頻錄制MediaRecorder之簡易的錄音軟件實(shí)現(xiàn)代碼,有需要的朋友可以參考一下2014-01-01