Android 用Animation-list實現逐幀動畫,android逐幀動畫圖片

來源:互聯網
上載者:User

Android 用Animation-list實現逐幀動畫,android逐幀動畫圖片
我們要實現的效果

準備資源檔放到 res/drawable檔案下中


light01.png

light02.png

light03.png

編寫 loading.xml 放到 res/drawable
<!--       animation-list :根標籤    oneshot :代表著是否只展示一遍,設定為false會不停的迴圈播放動畫      android :duration 表示該圖片的動畫時間長度   -->  <?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/light01"        android:duration="50"/>    <item        android:drawable="@drawable/light02"        android:duration="50"/>    <item        android:drawable="@drawable/light03"        android:duration="50"/></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="fill_parent"   android:layout_height="fill_parent"   android:orientation="vertical">    <ImageView android:id="@+id/main_img_loading"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:padding="5px"            android:src="@drawable/loading"/>     <Button android:id="@+id/main_bt_start"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:padding="5px"        android:text="開始" />    <Button android:id="@+id/main_bt_stop"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:padding="5px"        android:text="停止" /></LinearLayout>
在Activity中這樣來寫
bt_start.setOnClickListener(new OnClickListener()      {      @Override      public void onClick(View v) {      //擷取 AnimationDrawable        animationDrawable = (AnimationDrawable) animationIV.getDrawable();          //開始動畫        animationDrawable.start();      }  });   bt_stop.setOnClickListener(new OnClickListener()  {      @Override      public void onClick(View v) {     //擷取 AnimationDrawable          animationDrawable = (AnimationDrawable) animationIV.getDrawable();         //停止動畫         animationDrawable.stop();      }  });  

有興趣的童鞋可以關注我的Blog,我的專欄會持續更新Android Studio 權威教程,以及2015 I/O大會上的NDK的配置和編譯,我也全部會分享給大家。
並且我收到了CSND 的講師邀請,後期我會把這些Android Studio的使用教程錄製成視頻。

/** * -------------- * 歡迎轉載   |  轉載請註明 * -------------- * 如果對你有協助,請點擊|頂| * -------------- * 請保持謙遜 | 你會走的更遠 * -------------- * @author zsl * @github https://github.com/yy1300326388 * @blog http://blog.csdn.net/yy1300326388 */

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.