2010-07-26 59 views
-1

我必須重複使用Thread和AnimationDrawable的圖像序列,但它不能連續工作。我不想停止這個動畫,直到下一個活動通過按鈕點擊事件開始。android中的圖像動畫

這裏是我的Java代碼:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);{ 

final ImageView splashImage=(ImageView)findViewById(R.id.heartFunction); 
    splashImage.setBackgroundResource(R.drawable.slide_right); 
    splashAnimation = (AnimationDrawable) splashImage.getBackground(); 
} 




public void onWindowFocusChanged(boolean hasFocus) { 
    super.onWindowFocusChanged(hasFocus); 

    if (isFocused) { 
     //isFocused = false; 

     splashAnimation.start(); 
     var=false; 
     new Thread(new Runnable() { 
     public void run() { 
      try { 
       Thread.sleep(SPLASH_DISPLAY_LENGTH); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 
    }).start(); 
} 

slide_right.xml: -

<?xml version="1.0" encoding="utf-8"?> 
<animation-list 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="true"> 

<item android:drawable="@drawable/heartcolored0" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored2" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored4" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored5" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored6" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored7" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored8" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored9" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored10" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored11" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored12" android:duration="200" /> 
<item android:drawable="@drawable/heartcolored13" android:duration="200" /> 

</animation-list> 
+0

請編輯您的代碼以使其可讀。 – Sephy 2010-07-26 14:08:32

回答

2

如果你希望你的動畫contiuously然後運行需要設置android:oneshot="false"

你在說什麼之前只能跑過一次。

如果您想要動畫運行,直到您單擊屏幕以轉到下一個活動。開始時onWindowFocusChanged功能

@Override 
public void onWindowFocusChanged(boolean hasFocus){ 
    splashanimation.start(); 
} 

然後使用的onTouchEvent搭上觸摸,開始一個新的活動,並完成了老年活動動畫。

@Override 
public boolean onTouchEvent(MotionEvent event){ 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
      Intent i = new Intent(Anim.this, Main.class); 
      startActivity(i); 
      finish(); 
    } 
return true; 
} 

希望這會有所幫助,您的問題很難閱讀/理解。