Android button animations synchronize with timing

百般思念 提交于 2020-01-02 09:53:49

问题


I need an advice how to create some animations I want to add in my buttons. Actually I have the animation code, the thing which I need is how to set properly the timing of each one. Here is what I tried already :

    fest.setVisibility(View.INVISIBLE);
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            fest.setVisibility(View.VISIBLE);
            fest.startAnimation(anim);
            handler.removeCallbacks(this);
        }
    }, 500);

This is the things which I did for 7 buttons. First I set the visibility to invisible because I want to achieve the effect that they are appearing after 5 miliseconds after onCreate and for every next button I am increasing the delay time with 5 miliseconds so every of them to appear after the previos one. But the problem in this code is that when the next handler starts for the second button for example, the previos button is getting invisible for a part of the seconds and shows again(I hope someone understand what I mean).

Any suggestions for a bette implementation of something like that?

Thanks in advance!


回答1:


So here is the thing which fixed that problem. I used this for every button and it's working as I want :

    final Handler festHandler = new Handler();
    festHandler.postDelayed(new Runnable() {

        @Override
        public void run() {
             Animation anim = AnimationUtils.loadAnimation(Menu.this, R.anim.fadein);
             fest.setVisibility(View.VISIBLE);
             fest.startAnimation(anim);
             festHandler.removeCallbacks(this);
        }
    }, 400);


来源:https://stackoverflow.com/questions/12278228/android-button-animations-synchronize-with-timing

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