سؤال

لا بد لي من تكرار تسلسل الصور الذي أستخدمه مع Thread وAnimationDrawable ولكنه لا يعمل بشكل مستمر.لا أريد إيقاف هذه الرسوم المتحركة حتى يبدأ النشاط التالي من خلال حدث النقر على الزر.

هنا هو رمز جافا الخاص بي:

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>
هل كانت مفيدة؟

المحلول

إذا كنت تريد تشغيل الرسوم المتحركة الخاصة بك بشكل متواصل، فأنت بحاجة إلى ضبطها 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;
}

آمل أن يكون هذا مفيدًا، فمن الصعب جدًا قراءة/فهم سؤالك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top