2015-10-25 104 views
-1

我想實現一個動畫的蝴蝶,它應該通過點擊按鈕繞屏幕飛行。如何有效地實現它。如果我需要多個蝴蝶(可能是100+)是否會影響設備性能?我怎樣才能實現對翅膀的飛行效果。Android圖像動畫

  1. 是否有可能實現蝴蝶圖像的許多部分把 放在一起,並帶來這種飛的效果。
  2. 我可以使用的renderScript

請提供樣品code.i嘗試縮放動畫,但它並不如預期.ANY幫助明顯。

+0

這有幫助嗎? http://www.101apps.co.za/articles/frame-by-frame-animation-tutorial.html –

+0

hi @Mrad Mrad,該教程是好的,但我怎麼能實現該對象在屏幕上隨機飛行 –

回答

0

您可以通過在佈局中顯示簡單的gif來獲得相當好的性能。只需從您擁有的圖像中創建一個gif(使用一些gif maker即可 - 還有很多其他選項,只需搜索它即可)。爲了在應用程序中顯示gif,您可以使用自定義庫,如android-gif-drawable。實現類似於ImageView:

<pl.droidsonroids.gif.GifImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/your_butterfly_anim" 
/> 

這是一個簡單的動畫的可能性。

編輯:

int distance = 100; //the distance to move in pixels 
int duration = 500; //the duration of the animation in ms 

double direction = Math.random() * 2 * Math.PI; 

int translationX = Math.cos(direction) * distance; 
int translationY = Math.sin(direction) * distance; 

yourImageView.animate().translationX(translationX).translationY(translationY).setDuration(duration).start(); 

這應該給你的,你怎麼能得到它隨機飛行的一些初步想法。

+0

謝謝爲您的快速幫助 –

+0

嗨,大衛我想要隨機在屏幕上移動該對象看到我的問題 –

+0

我沒有在Android的動畫很多,但你可以嘗試使用[視圖動畫](http://開發人員.android.com/guide/topics/graphics/view-animation.html)在gifImageView上 - 認爲你可以通過它獲得一些好的結果。 – dabo