android幀切換播放動畫

來源:互聯網
上載者:User

標籤:android   圖片   動畫   

android動畫的簡單使用

這裡通過不斷切換圖片,達成動畫效果。

在布局中,定義一個ImageButton控制項

並設定好其位置。


//布局檔案

//很簡單,就一個控制項

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".AnimActivity" >    <ImageView        android:id="@+id/anim_id"        android:layout_width="70dp"        android:layout_height="50dp"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true" /></RelativeLayout>


//res/anim/anim_test.xml動畫

//裡面涉及到間隔、圖片切換。

//另外在第一張與最後一張,我用了透明的圖片作為填充。

//以解決動畫播放完畢後,最後一張圖片沒有消失的現象。

<?xml version="1.0" encoding="utf-8"?><animation-list android:oneshot="true"    xmlns:android="http://schemas.android.com/apk/res/android">    <item android:duration="50" android:drawable="@drawable/null_06" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num10" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num9" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num8" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num7" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num6" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num5" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num4" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num3" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num2" />    <item android:duration="1000" android:drawable="@drawable/bs_preview_item_num1" />    <item android:duration="1000" android:drawable="@drawable/null_06" /></animation-list>


//函數中啟動動畫

//直接調用該方法即可


//進入選擇介面後播放

private void playReadyAnim(){//播放動畫ImageView animImg = (ImageView)findViewById(R.id.anim_id);animImg.setBackgroundResource(R.anim.anim_test);Object ob = animImg.getBackground();anim = (AnimationDrawable) ob;anim.stop();anim.start();}


本文出自 “爬過山見過海” 部落格,請務必保留此出處http://670176656.blog.51cto.com/4500575/1601538

android幀切換播放動畫

聯繫我們

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