Android 動畫詳解之Frame動畫 (Drawable Animation),androiddrawable

來源:互聯網
上載者:User

Android 動畫詳解之Frame動畫 (Drawable Animation),androiddrawable

Frame動畫就像是gif圖,通過一些靜態圖片來達到動畫的效果。

Android sdk中的AnimationDrawable就是專門針對Frame動畫,當然Frame動畫也可在java代碼或者xml中寫,但是提倡大家還是在xml中寫,先上個。


<span style="font-size:18px;"><?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/market_loading_01"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_02"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_03"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_04"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_05"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_06"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_07"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_08"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_09"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_10"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_11"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_12"        android:duration="100"/></animation-list></span>

Frame動畫在xml中的根節點是<animation-list>其中的oneshot=false是迴圈播放,為true的話則播放至最後一張圖片就會停止播放,在java中調用

ImageView imageView;AnimationDrawable animationDrawable;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageView = (ImageView) findViewById(R.id.image);imageView.setBackgroundResource(R.drawable.drawable_progress);animationDrawable = (AnimationDrawable) imageView.getBackground();animationDrawable.start();

因為Frame 動畫是有一堆靜態圖構成的所以,可以當成background。


用java代碼寫的話

  AnimationDrawable animationDrawable2 = new AnimationDrawable();  Drawable drawable = getResources().getDrawable(R.drawable.fengjing_1);  Drawable drawable2 = getResources().getDrawable(R.drawable.fengjing_2);  Drawable drawable3 = getResources().getDrawable(R.drawable.fengjing_3);        animationDrawable2.addFrame(drawable, 1000);        animationDrawable2.addFrame(drawable2, 1000);        animationDrawable2.addFrame(drawable3, 1000);        animationDrawable2.setOneShot(false);        imageView.setBackgroundDrawable(animationDrawable2);        animationDrawable2.start();

恩。。就是這樣了,Frame 動畫瞭解到這已經差不多了。


項目源碼


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.