how do i run AnimationDrawable 3 times

时光总嘲笑我的痴心妄想 提交于 2019-12-11 01:58:09

问题


Hi again everyone and thanks for your help last time. Thanks also for any help you all give me on this one!

So i have an amimationDrawable of a coinSpinning.

    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="true">
    <item android:drawable="@drawable/coinflip1" android:duration="25" />
    <item android:drawable="@drawable/coinflip2" android:duration="25" />
    <item android:drawable="@drawable/coinflip3" android:duration="25" />
    <item android:drawable="@drawable/coinflip4" android:duration="25" />
    <item android:drawable="@drawable/coinflip5" android:duration="25" />
    <item android:drawable="@drawable/coinflip6" android:duration="25" />
    <item android:drawable="@drawable/coinflip7" android:duration="25" />
    <item android:drawable="@drawable/coinflip8" android:duration="25" />
    <item android:drawable="@drawable/coinflip9" android:duration="25" />
    <item android:drawable="@drawable/coinflip10" android:duration="25" />
    <item android:drawable="@drawable/coinflip11" android:duration="25" />
    <item android:drawable="@drawable/coinflip12" android:duration="25" />
    </animation-list>

this is my method that spins the coin after a button onClick

    public void spinCoin(){

        final ImageView coinAmina = (ImageView) findViewById(R.id.imageView1);
        coinAmina.setBackgroundResource(R.anim.coin_spin_heads); 
        coinAmina.post(new Runnable() {

            @Override
            public void run() {
                frameAnimation = (AnimationDrawable) coinAmina.getBackground();
                frameAnimation.start();
            }
        }); 

        //end of coin spin
        }

i also have AnimationDrawable frameAnimation; before onCreate

it runs fine, but my problem has been trying to run it a certain amount of time eg 3 ive tried to loop the coinSpin() then frameAnimation.stop but no good

ive also tryed Thread.sleep(500) with setOneShot(false) then changed to true after the sleep

all i want to do is run the animation whatever amount of time i like. other problem is when i have 2 coins to spin only one does but that should be another question

i understand setOneshot(true) runs it once and false runs it over and over...but how do i stop it

any help would be greatly appriciated

来源:https://stackoverflow.com/questions/22268946/how-do-i-run-animationdrawable-3-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!