получить текущий кадр анимации с помощью AnimationDrawable на Android - PullRequest
0 голосов
/ 24 июня 2019

У меня есть два изображения для анимации.у каждого из них есть три изображения.первая анимация имеет кнопку старт / стоп.вторая анимация воспроизводится автоматически.когда 3-й кадр 1-й анимации и 3-й кадр 2-й анимации воспроизводятся одновременно, я хочу остановить всю анимацию.как я могу проверить, воспроизводится ли 3-й кадр для обоих изображений одновременно?

GameActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_game)

        val sonImage = findViewById<ImageView>(R.id.sonid).apply {
            setBackgroundResource(R.drawable.son)
            sonAnimation = background as AnimationDrawable
        }

        val fatherImage = findViewById<ImageView>(R.id.fatherid).apply {
            setBackgroundResource(R.drawable.father)
            fatherAnimation = background as AnimationDrawable

        }

        startPlay.setOnClickListener {
            sonAnimation.start()
        }

        stop.setOnClickListener {
            sonAnimation.stop()
        }

        val handler = Handler()
        handler.postDelayed(object : Runnable {
            override fun run() {
                randomValues = Random.nextLong(0, 10)
                fatherAnimation.start()
                handler.postDelayed(this, (randomValues*1000)+941)

            }
        }, 2000)

        val handler1 = Handler()
        handler1.postDelayed(object : Runnable {
            override fun run() {
                fatherAnimation.stop()
                handler1.postDelayed(this, (randomValues*1000)+940)

            }
        }, 2940)

    }

son.xml

<?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
                    android:oneshot="false">
        <item android:drawable="@drawable/son1" android:duration="235" />
        <item android:drawable="@drawable/son2" android:duration="235" />
        <item android:drawable="@drawable/son3" android:duration="235" />
    </animation-list>

папа.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
                android:oneshot="false" >
    <item android:drawable="@drawable/father1" android:duration="235" />
    <item android:drawable="@drawable/father2" android:duration="235" />
    <item android:drawable="@drawable/father3" android:duration="235" />
</animation-list>
...