2014-12-29 44 views
0

我想在屏幕上有20個對象。每個對象都是動畫的,基本上由5個圖像幀組成。例如,讓我們說一個有煙冒出來的房子。我想知道使用哪種方法(以及爲什麼)AnimationDrawable或OnDraw動畫圖像

1-動畫可繪製的圖像是在xml文件中的動畫集中定義的圖像。動畫被設定爲無限

2-自定義視圖延伸的ImageView其中I設定在OnDraw的方法某個幀所需要的圖像,並保持在該方法結束時調用的onDraw(或無效)

3-其他一些方法

我傾向於使用容易第一種方法,但我不知道的正確方法(或爲什麼我不應該用我的)

謝謝你這麼多

+0

使用'AnimationDrawable'。沒有必要重新發明輪子。 –

回答

0

是的,首先一個很簡單,很好用oach。我之前做過。活動初始化如下:

ImageView imageViewAnimation; 
    private AnimationDrawable independentAnimation; 

    imageViewAnimation = (ImageView) findViewById(R.id.imageViewAnimation); 

     // set the animation drawable as background 
     // here demo_logo_animation is an XML 

     imageViewAnimation 
       .setBackgroundResource(R.drawable.demo_logo_animation); 
     // create an animation drawable using the background 


     independentAnimation = (AnimationDrawable) imageViewAnimation 
       .getBackground(); 

     // start the animation 
     imageViewAnimation.post(new Runnable() { 

      @Override 
      public void run() { 
       // fOR 2.3 DEVICES 
       independentAnimation.start(); 
      } 
     }); 

將所有圖像& demo_logo_animation.xml在RES /繪製文件夾中。 demo_logo_animation.xml中的屬性從上到下依次運行。所以,仔細安置。然後demo_logo_animation.xml看起來像

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="true" > 

    <item 
     android:drawable="@drawable/itv001" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv003" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv006" 
     android:duration="@string/log_in_duration"/> 


    <item 
     android:drawable="@drawable/itv009" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv012" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv015" 
     android:duration="@string/log_in_duration"/> 


    <item 
     android:drawable="@drawable/itv018" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv021" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv024" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv027" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv030" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv033" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv036" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv039" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv042" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv045" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv048" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv051" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv054" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv057" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv060" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv063" 
     android:duration="@string/log_in_duration"/> 




    <item 
     android:drawable="@drawable/itv066" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv069" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv072" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv075" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv078" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv081" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv084" 
     android:duration="@string/log_in_duration"/> 

    <item 
     android:drawable="@drawable/itv087" 
     android:duration="@string/log_in_duration"/> 


</animation-list> 
+0

謝謝..我認爲這兩種選擇的表現都是一樣的,我也不會失去很多 – Snake