анимация изображения в андроид - PullRequest
0 голосов
/ 26 июля 2010

Я должен повторить последовательность изображений, которую я использую с Thread и AnimationDrawable, но она не работает непрерывно. Я не хочу останавливать эту анимацию, пока не будет запущено следующее действие через событие нажатия кнопки.

Вот мой код 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>

1 Ответ

2 голосов
/ 26 июля 2010

Если вы хотите, чтобы ваша анимация продолжалась непрерывно, вам нужно установить 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;
}

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

...