文章目錄
1、逐幀動畫
(一)逐幀動畫概念
- 逐幀動畫(Frame-by-Frame Animation)是一種常見的動畫形式,其原理是在「連續關鍵幀」中分解動畫動做,也就是在時間軸的每幀上逐幀繪製不一樣的內容,使其連續播放而成動畫。 由於逐幀動畫的幀序列內容不同,不但給製做增長了負擔,並且最終輸出的文件量也很大,但它的優點也很明顯,逐幀動畫具備很是大的靈活性,幾乎能夠表現任何想表現的內容,而它相似與電影的播放模式,很適合於表演細膩的動畫。例如人物或動物急劇轉身、 頭髮及衣服的飄動、走路、說話以及精緻的3D效果等等。
(二)逐幀動畫實現方式
- 利用動畫資源文件實現逐幀動畫
- 利用Thread和Handler來實現逐幀動畫
- 利用Timer和TimerTask來實現逐幀動畫
2、利用動畫資源文件實現逐幀動畫 - 功夫熊貓
(一)運行效果
(二)實現步驟
一、建立安卓應用【PandaAnimation01】
二、將圖片素材拷貝到drawable目錄
三、建立動畫資源文件 - panda_animator.xml
- 在drawable目錄裏建立panda_animator.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/fat_po_f1" android:duration="60"/> <item android:drawable="@drawable/fat_po_f2" android:duration="60"/> <item android:drawable="@drawable/fat_po_f3" android:duration="60"/> <item android:drawable="@drawable/fat_po_f4" android:duration="60"/> <item android:drawable="@drawable/fat_po_f5" android:duration="60"/> <item android:drawable="@drawable/fat_po_f6" android:duration="60"/> <item android:drawable="@drawable/fat_po_f7" android:duration="60"/> <item android:drawable="@drawable/fat_po_f8" android:duration="60"/> <item android:drawable="@drawable/fat_po_f9" android:duration="60"/> <item android:drawable="@drawable/fat_po_f10" android:duration="60"/> <item android:drawable="@drawable/fat_po_f11" android:duration="60"/> <item android:drawable="@drawable/fat_po_f12" android:duration="60"/> <item android:drawable="@drawable/fat_po_f13" android:duration="60"/> <item android:drawable="@drawable/fat_po_f14" android:duration="60"/> <item android:drawable="@drawable/fat_po_f15" android:duration="60"/> <item android:drawable="@drawable/fat_po_f16" android:duration="60"/> <item android:drawable="@drawable/fat_po_f17" android:duration="60"/> <item android:drawable="@drawable/fat_po_f18" android:duration="60"/> <item android:drawable="@drawable/fat_po_f19" android:duration="60"/> <item android:drawable="@drawable/fat_po_f20" android:duration="60"/> <item android:drawable="@drawable/fat_po_f21" android:duration="60"/> <item android:drawable="@drawable/fat_po_f22" android:duration="60"/> <item android:drawable="@drawable/fat_po_f23" android:duration="60"/> <item android:drawable="@drawable/fat_po_f24" android:duration="60"/> <item android:drawable="@drawable/fat_po_f25" android:duration="60"/> <item android:drawable="@drawable/fat_po_f26" android:duration="60"/> <item android:drawable="@drawable/fat_po_f27" android:duration="60"/> </animation-list>
四、主佈局資源文件activity_main.xml
<?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:gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/iv_panda" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/panda_animator" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" > <Button android:id="@+id/btnPlay" android:layout_width="150dp" android:layout_height="wrap_content" android:onClick="doPlay" android:text="@string/play" /> <Button android:id="@+id/btnStop" android:layout_width="150dp" android:layout_height="wrap_content" android:onClick="doStop" android:text="@string/stop" /> </LinearLayout> </LinearLayout>
本文同步分享在 博客「howard2005」(CSDN)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。android