Android Animation 幀動畫監聽結束的方法

來源:互聯網
上載者:User

 

這個問題用中文搜了很久一直沒有解決,今天嘗試用英文在Google上搜了一下,開啟第一個網頁就把困擾的很久的問題解決了

 

 

問題描述:幀動畫連續播放--android 幀動畫沒有提供結束動作的監聽方法,怎麼實現播放完一個動畫之後接著播放第二個動畫呢?

 

 

正確方法1:

 

 

public void mmswoon(){ 

        imageView.setBackgroundResource(R.anim.mmswoon); 

        AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground(); 

        animationDrawable.start(); 

         

        int duration = 0; 

        for(int i=0;i<animationDrawable.getNumberOfFrames();i++){ 

            duration += animationDrawable.getDuration(i); 

        } 

        Handler handler = new Handler(); 

        handler.postDelayed(new Runnable() { 

            public void run() { 

               //此處調用第二個動畫播放方法   

            } 

        }, duration); 

         

    } 

duration是第一個動畫播放的總時間

 

PS :自己試過了,可以實現效果

正確方法2:

 

 

this.q_pic_view.setImageResource(0); 

    this.q_pic_view.setBackgroundResource(R.drawable.animation_test); 

    AnimationDrawable correct_animation = (AnimationDrawable) this.q_pic_view.getBackground(); 

    correct_animation.start(); 

 

    //here I tried to implement option C but it didn't work 

    while(correct_animation.isRunning()){ 

        try { 

           Thread.sleep(20); 

        } catch (InterruptedException e) { 

           // TODO Auto-generated catch block 

           e.printStackTrace(); 

        } 

    } 

這個方法沒有試過

 

摘自 wangxin的專欄

聯繫我們

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