I can't start the alternate animation.

for (int i = 0; i < txts.size(); i++) { AnimationDrawable animationDrawable = (AnimationDrawable) txts.get(i).getBackground(); animationDrawable.setEnterFadeDuration(2000); animationDrawable.setExitFadeDuration(4000); animationDrawable.start(); try { sleep(500); } catch (Exception e) { sasha(String.valueOf(e)); } } 

I tried to put this code in onStart, onCreate, onResume. First a black screen appears, i.e. waits until the loop stops and only then starts all the animations at once. Help me please.

    1 answer 1

    Read about AnimatorSet: here and here and of course the buzz, everything is there

     AnimatorSet as = new AnimatorSet(); List list = new ArrayList(); for (int i = 0; i < txts.size(); i++) { AnimationDrawable animationDrawable = (AnimationDrawable) txts.get(i).getBackground(); animationDrawable.setEnterFadeDuration(2000); animationDrawable.setExitFadeDuration(4000); list.add(animationDrawable); } as.playSequentially(list); //as.setDuration(6000); точно не помню, нужно ли здесь - методом эксперемнта пробуйте as.start(); // и старт там где вам нужно выполнить эту анимацию. 

    PS You would first add a button and start the animation on the button, and it will be clearer and clearer

    • Thanks for the answer, but the studio just gives an error: AnimationDrawable cannot be cast to android.animation.Animator - Sasha Kriss
    • @ SashaKriss See, here what the situation is, there is an Animation library and Animator, Animation is not recommended to use now because of memory leaks, instead it is advisable to use Animator and didn’t pay what you use animation. The other day I will fix it. Ask the question what exactly should happen. - Valeriy