將每個幀都作爲可繪製文件夾中的單獨圖像。在此之後,使用XML來定義幀(例如,ANIMATED.xml)
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/0" android:duration="50" />
<item android:drawable="@drawable/1" android:duration="50" />
<item android:drawable="@drawable/2" android:duration="50" />
<item android:drawable="@drawable/3" android:duration="50" />
<item android:drawable="@drawable/4" android:duration="50" />
<item android:drawable="@drawable/5" 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.moving_image);
img.setBackgroundResource(R.drawable.ANIMATED.xml);
// 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();
你有沒有想過使用videoview的? –
@harvey_slash通過VideoView類後,我認爲不適合我的要求。根據我的理解,VideoView和MediaController提供了暫停選項,但我不需要這些功能。 – Sri