2013-01-06 102 views
1

我有以下XML文件來定義我的幀動畫:設置一個監聽器,幀動畫

<animation-list 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false"> 
<item android:drawable="@drawable/youme_blink_frame_0000" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0001" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0002" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0003" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0004" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0005" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0006" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0007" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0008" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0009" android:duration="40" /> 
<item android:drawable="@drawable/youme_blink_frame_0010" android:duration="40" /> 
</animation-list> 

然後,我有以下代碼:

Animation mAnim = AnimationUtils.loadAnimation(this, R.anim.blink); 
    mAnim.setAnimationListener(this); 

    ImageView img = (ImageView)findViewById(R.id.animationImage); 
    img.clearAnimation(); 
    img.setAnimation(mAnim); 
    img.startAnimation(mAnim); 

此代碼生成異常與錯誤「未找到動畫文件」。 是不是一個框架動畫被認爲是一個動畫或者我做錯了什麼?

感謝, 西蒙

回答

3

逐幀動畫是一個AnimationDrawable不是動畫。你所做的是將它作爲動畫使用,而這是異常的原因,沒有帶有該名稱的動畫文件就有可繪製文件。 使用AnimationDrawable使用該代碼段

// 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(); 

約AnimationDrawable更多信息,請參閱documentation

+1

這不回答這個問題如何動畫監聽器添加到它 – ERJAN