Android怎樣播放多張圖片形成一個動畫

來源:互聯網
上載者:User

Android怎樣播放多張圖片形成一個動畫

在Android裡可以逐幀的播放圖片,然後產生一種動態效果,準備好幾張連續的圖片,然後在於來源程式res檔案夾下建立anim檔案夾,然後建立一個XML

XML代碼如下:

  1. version="1.0" encoding="utf-8"?> xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:oneshot="true"> android:drawable="@drawable/c1" android:duration="200" />
  3. android:drawable="@drawable/c2" android:duration="200" /> android:drawable="@drawable/c3" android:duration="200" />
  4. android:drawable="@drawable/c4" android:duration="200" /> android:drawable="@drawable/c5" android:duration="200" />
  5. android:drawable="@drawable/c6" android:duration="200" />

     

     

    其中c1,c2,c3,c4,c5,c6是加入的圖片的名稱。

    在表單裡面放置一個ImageView控制項,並在代碼中編寫:

    _imageView1 =(ImageView)findViewById(R.id.imageView1);//放置的ImageView控制項

     

    1. //設定動畫背景 _imageView1.setBackgroundResource(R.anim.animation_list);//其中R.anim.animation_list就是上一步準備的動畫描述檔案的資源名
    2. //獲得動畫對象 _animaition = (AnimationDrawable)_imageView1.getBackground();
    3. 最後,就可以啟動動畫了,代碼如下: //是否僅僅啟動一次?
    4. _animaition.setOneShot(false); if(_animaition.isRunning())//是否正在運行?
    5. { _animaition.stop();//停止
    6. } _animaition.start();//啟動

聯繫我們

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