Android -- 逐幀動畫

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   使用   

在處理耗時工作的時候,大多數會彈出一個載入的框,裡面有一個連續旋轉的圖片,很多時候都是用一張圖片,使用rotate來設定旋轉,不過看起來不太美觀,沒有形象感,在3.0之前Android有兩種動畫效果分別是補間動畫和幀動畫,用一張圖片實現的是使用補間動畫,定義給出兩個主要畫面格,通過一些演算法將給定屬性值在給定的時間內在兩個主要畫面格間漸層。

動畫布局                                                                                    

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item        android:drawable="@drawable/appstore"        android:duration="200"/>    <item        android:drawable="@drawable/calculator"        android:duration="200"/>    <item        android:drawable="@drawable/camera"        android:duration="200"/>    <item        android:drawable="@drawable/clock"        android:duration="200"/>    <item        android:drawable="@drawable/compass"        android:duration="200"/>    <item        android:drawable="@drawable/contacts"        android:duration="200"/>    <item        android:drawable="@drawable/facetime"        android:duration="200"/>    <item        android:drawable="@drawable/game_center"        android:duration="200"/>    <item        android:drawable="@drawable/itunes_store"        android:duration="200"/>    <item        android:drawable="@drawable/mail"        android:duration="200"/></animation-list>

代碼                                                                                          

public class MainActivity extends Activity {    private ImageView iv;    private AnimationDrawable ani;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        iv = (ImageView) findViewById(R.id.iv);        iv.setBackgroundResource(R.drawable.ic_list);        ani = (AnimationDrawable) iv.getBackground();    }    public void click(View view) {        ani.start();    }}

我是天王蓋地虎的分割線                                                                

 

原始碼:http://pan.baidu.com/s/1dD1Qx01

幀動畫.zip

 

 

 

轉載請註明出處:http://www.cnblogs.com/yydcdut

聯繫我們

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