2010-07-26 2 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

ответ

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; 
} 

Надеюсь, это поможет, ваш вопрос очень трудно прочитать/понять.