2012-05-30 101 views
1

我創建animation.xml文件,在其中我已經加了我幀動畫的東西,但它不工作我在活動課叫5這爲後續....動畫的android

animation = (ImageView)findViewById(R.id.imageAnimation); 
     animation.setBackgroundResource(R.drawable.animation);  // the frame-by-frame animation defined as a xml file within the drawable folder 
     AnimationDrawable frameAnimation = 
       (AnimationDrawable) animation.getBackground(); 
      frameAnimation.start(); 

能任何一個可以告訴我什麼該

animation.xmal文件是問題

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false"> 

    <item android:drawable="@drawable/anatomy_5" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_6" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_7" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_8" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_9" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_10" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_11" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_12" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_13" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_14" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_15" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_16" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_17" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_18" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_19" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_20" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_21" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_22" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_23" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_24" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_25" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_26" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_27" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_28" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_29" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_30" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_31" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_32" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_33" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_34" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_35" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_36" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_37" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_38" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_39" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_40" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_41" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_42" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_43" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_44" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_45" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_46" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_47" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_48" android:duration="50" /> 
    <item android:drawable="@drawable/anatomy_49" android:duration="50" /> 

</animation-list> 
+0

試試這個http://stackoverflow.com/questions/2785336/starting-frame-by-frame-animation –

回答

2

試試這個

把你animation.xml文件夾anim

簡單的動畫

Animation rAnim = AnimationUtils.loadAnimation(your_context, R.anim.animation); 
animation.startAnimation(rAnim); 

其中animation是您imageview

更新

可繪製動畫

AnimationDrawable rocketAnimation; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image); 
     rocketImage.setBackgroundResource(R.drawable.rocket_thrust); 
     rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); 
     final Thread thread = new Thread(new Runnable() 
    { 
    @Override 
    public void run() 
    { wait(1000);  
    activity.runOnUiThread(new Runnable() {@Override public void run() 
    { 
    rocketAnimation.start(); 
    }}); 
    } 
}); 
thread.start(); 

    } 

    public boolean onTouchEvent(MotionEvent event) { 
     if (event.getAction() == MotionEvent.ACTION_DOWN) { 
     rocketAnimation.start(); 
     return true; 
     } 
     return super.onTouchEvent(event); 
    } 
+0

什麼行動?你可以解釋嗎? – Ashishsingh

+0

檢查我的答案它是競爭 –

+1

它引發我運行時異常引起:java.lang.RuntimeException:未知的動畫名稱:animation-list – Ashishsingh

3

截至drawable animation example頁面底部看到:

需要注意的是不能的 的onCreate()方法中調用呼籲 AnimationDrawable的start()方法是很重要的活動,因爲AnimationDrawable尚未完全附着 到窗口。如果你想立即播放動畫,而不需要 互動,那麼你可能想從 onWindowFocusChanged()方法在你的活動,這將調用 時,Android將你的窗口成爲焦點調用它。

希望它可以幫助..;)乾杯

+1

這是最好的點之一g在這裏。在OnCreate()'期間不開始動畫! – Levit

1

新建文件夾阿尼姆資源,把你的animation.xml動畫文件夾,不是用這種方式

Animation anim = AnimationUtils.loadAnimation(this,R.anim.animation); 
imageview.setAnimation(anim); 
or 
imageview.startAnimation(anim); 
+2

它拋出java.lang.RuntimeException:未知的動畫名稱:animation-list – Ashishsingh