- 一類是Tween動畫,就是對場景裡的物件不斷的進行圖像變化來產生動畫效果(旋轉、平移、放縮和漸變)。
- 第二類就是Frame動畫,即順序的播放事先做好的圖像,與gif圖片原理類似。
Frame Animation (影格動畫、禎動畫)
其實使用起來比較簡單,首先需要創建一個AnimationDrawable對象,通過addFrame方法把每一幀要顯示的內容添加進去,最後通過Start方法來播放動畫。 同時還有設置循環setOneShot等方法可供使用。要先增加我們的xml動畫定義檔:
<!-- Animation frames are wheel0.png -- wheel5.png files inside the
res/drawable/ folder -->
<animation-list android:id="selected" android:oneshot="false">
<item android:drawable="@drawable/wheel0" android:duration="50" />
<item android:drawable="@drawable/wheel1" android:duration="50" />
<item android:drawable="@drawable/wheel2" android:duration="50" />
<item android:drawable="@drawable/wheel3" android:duration="50" />
<item android:drawable="@drawable/wheel4" android:duration="50" />
<item android:drawable="@drawable/wheel5" android:duration="50" />
</animation-list>
然後再程式碼添加上:// Load the ImageView that will host the animation and // set its background to our AnimationDrawable XML resource. ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image); img.setBackgroundResource(R.drawable.spin_animation); // Get the background, which has been compiled to an AnimationDrawable object. AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); // Start the animation (looped playback by default). frameAnimation.start()
沒有留言 :
張貼留言