Android逐帧动画的实现
生活随笔
收集整理的這篇文章主要介紹了
Android逐帧动画的实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉自http://blog.csdn.net/jwzhangjie/article/details/18323101 分類:?android?視頻播放器制作2014-01-15 21:39?3315人閱讀?評論(0)?收藏?舉報 <?xml?version="1.0"?encoding="utf-8"?>?? <!--??? ????根標簽為animation-list,其中oneshot代表著是否只展示一遍,設置為false會不停的循環播放動畫?? ????根標簽下,通過item標簽對動畫中的每一個圖片進行聲明?? ????android:duration?表示展示所用的該圖片的時間長度?? ?-->?? ?<animation-list?? ?????xmlns:android="http://schemas.android.com/apk/res/android"?? ?????android:oneshot="false"?? ?????>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_1"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_2"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_3"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_4"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_5"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_6"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_7"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_8"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_9"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_10"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_11"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/qb_tenpay_loading_12"?android:duration="150"></item>?? ?</animation-list>?? ??? load_animation_2.xml <?xml?version="1.0"?encoding="utf-8"?>?? <!--??? ????根標簽為animation-list,其中oneshot代表著是否只展示一遍,設置為false會不停的循環播放動畫?? ????根標簽下,通過item標簽對動畫中的每一個圖片進行聲明?? ????android:duration?表示展示所用的該圖片的時間長度?? ?-->?? ?<animation-list?? ?????xmlns:android="http://schemas.android.com/apk/res/android"?? ?????android:oneshot="false"?? ?????>?? ????<item?android:drawable="@drawable/common_loading_0"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_1"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_2"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_3"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_4"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_5"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_6"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_7"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_8"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_9"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_10"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/common_loading_11"?android:duration="150"></item>?? ?</animation-list>?? wifi_animation_1.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/wifi_1"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/wifi_2"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/wifi_3"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/wifi_4"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/wifi_5"?android:duration="150"></item>?? ????<item?android:drawable="@drawable/wifi_6"?android:duration="150"></item>?? ?</animation-list>?? 布局文件: <?xml?version="1.0"?encoding="utf-8"?>?? <RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"?? ????android:layout_width="match_parent"?? ????android:layout_height="match_parent"?? ????android:orientation="vertical"?>?? ?? ????<Button?? ????????android:layout_width="wrap_content"?? ????????android:layout_height="wrap_content"?? ????????android:text="動畫加載1"?? ????????android:id="@android:id/button1"?? ????????></Button>?? ????<Button??? ????????android:id="@android:id/button2"?? ????????android:layout_width="wrap_content"?? ????????android:layout_height="wrap_content"?? ????????android:layout_toRightOf="@android:id/button1"?? ????????android:layout_marginLeft="20dip"?? ????????android:text="動畫加載2"?? ????????/>?? ????<Button??? ????????android:id="@android:id/button3"?? ????????android:layout_width="wrap_content"?? ????????android:layout_height="wrap_content"?? ????????android:layout_toRightOf="@android:id/button2"?? ????????android:layout_marginLeft="20dip"?? ????????android:text="動畫wifi1"?? ????????/>?? ????<ImageView??? ????????android:id="@+id/animationIV"?? ????????android:layout_width="wrap_content"?? ????????android:layout_height="wrap_content"?? ????????android:layout_centerInParent="true"?? ????????android:contentDescription="@string/app_name"?? ????????/>?? ?????? ????<ImageView?? ????????android:id="@+id/animationIV2"?? ????????android:layout_width="wrap_content"?? ????????android:layout_height="wrap_content"?? ????????android:layout_toRightOf="@id/animationIV"?? ????????android:src="@anim/load_animation_2"?? ????????android:contentDescription="@string/app_name"?? ????????android:layout_alignBottom="@id/animationIV"?? ????????android:layout_marginLeft="30dip"?? ????????/>?? ?????? ????<ImageView?? ????????android:id="@+id/animationIV3"?? ????????android:layout_width="wrap_content"?? ????????android:layout_height="wrap_content"?? ????????android:layout_above="@id/animationIV"?? ????????android:contentDescription="@string/app_name"?? ????????android:layout_marginTop="20dip"?? ????????/>?? </RelativeLayout>?? [java]?view plaincopy public?class?Test?extends?BaseActivity{?? ?? ????private?Button?button1,button2,button3;?? ????private?ImageView?animationIV;?? ????private?ImageView?animationIV2;?? ????private?ImageView?animationIV3;?? ????private?AnimationDrawable?AniDraw,?AniDraw2,?AniDraw3;?? ????@Override?? ????protected?void?onCreate(Bundle?savedInstanceState)?{?? ????????super.onCreate(savedInstanceState);?? ????????setContentView(R.layout.test);?? ????????button1?=?(Button)findViewById(android.R.id.button1);?? ????????button1.setOnClickListener(new?OnClickListener()?{?? ????????????@Override?? ????????????public?void?onClick(View?v)?{?? ????????????????if?(AniDraw.isRunning())?{?? ????????????????????AniDraw.stop();?? ????????????????}else?{?? ????????????????????AniDraw.start();?? ????????????????}?? ?????????????????? ????????????}?? ????????});?? ????????button2?=?(Button)findViewById(android.R.id.button2);?? ????????button2.setOnClickListener(new?OnClickListener()?{?? ????????????@Override?? ????????????public?void?onClick(View?v)?{?? ????????????????if?(AniDraw2.isRunning())?{?? ????????????????????AniDraw2.stop();?? ????????????????}else?{?? ????????????????????AniDraw2.start();?? ????????????????}?? ????????????}?? ????????});?? ????????button3?=?(Button)findViewById(android.R.id.button3);?? ????????button3.setOnClickListener(new?OnClickListener()?{?? ????????????@Override?? ????????????public?void?onClick(View?v)?{?? ????????????????if?(AniDraw3.isRunning())?{?? ????????????????????AniDraw3.stop();?? ????????????????}else?{?? ????????????????????AniDraw3.start();?? ????????????????}?? ????????????}?? ????????});?? ?????????? ????????animationIV?=?(ImageView)findViewById(R.id.animationIV);?? ????????/**? ?????????*?這里設置的是setBackgroundResource,那么你獲取的時候通過getBackground? ?????????*/?? ????????animationIV.setBackgroundResource(R.anim.load_animation_1);?? ????????AniDraw?=?(AnimationDrawable)animationIV.getBackground();?? ????????/**? ?????????*?在xml里面通過src來設置跟在代碼里面使用setImageResource獲取的時候通過getDrawable? ?????????*?例如:animationIV2.setImageResource(R.anim.load_animation_2);是一樣的? ?????????*/?? ????????animationIV2?=?(ImageView)findViewById(R.id.animationIV2);?? ????????AniDraw2?=?(AnimationDrawable)animationIV2.getDrawable();?? ????????animationIV3?=?(ImageView)findViewById(R.id.animationIV3);?? ????????animationIV3.setImageResource(R.anim.wifi_animation_1);?? ????????AniDraw3?=?(AnimationDrawable)animationIV3.getDrawable();?? ????}
在處理耗時工作的時候,大多數會彈出一個加載的框,里面有一個連續旋轉的圖片,很多時候都是用一張圖片,使用rotate來設定旋轉,不過看起來不太美觀,沒有形象感,在3.0之前Android有兩種動畫效果分別是補間動畫和幀動畫,用一張圖片實現的是使用補間動畫,定義給出兩個關鍵幀,通過一些算法將給定屬性值在給定的時間內在兩個關鍵幀間漸變。我個人比較傾向的是幀動畫,不過這個需要美工的支持,還有一種方式就是通過反編譯其他的軟件獲取圖片,我不是美工也沒有美工的支持,所以就解壓QQ的apk,獲取它里面的顯示加載動畫的圖片,圖片資源http://download.csdn.net/download/jwzhangjie/6852981。
看看如何實現的
load_animation_1.xml
?
[html]?view plaincopy?
?
[html]?view plaincopy?
?
[html]?view plaincopy?
?
[html]?view plaincopy轉載于:https://www.cnblogs.com/Small-Life/p/4320258.html
總結
以上是生活随笔為你收集整理的Android逐帧动画的实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安装axios太慢解决方案
- 下一篇: Android实训——图书管理系统