Animation not starting until UI updates or touch event

混江龙づ霸主 提交于 2019-12-03 01:13:00
Jukurrpa

A little more research showed that my problem was the same a this question: Layout animation not working on first run

The flashView's visibility was set to GONE by default (causing the Animation not to start immediately as the View had never been rendered), so I just need to set it to INVISIBLE before calling flashView.startAnimation()

If setting the View to VISIBLE won't work, as was in my case, it helped for me to call requestLayout() before starting the Animation, like so:

Animation an = new Animation() {
...   
view.requestLayout();
view.startAnimation(an);

In my case, my View was 0dip high which prevented onAnimationStart from being called, this helped me around that problem.

This worked for me:

view.setVisibility(View.VISIBLE);
view.startAnimation(animation);

I had to set the view to VISIBLE (not INVISIBLE, neither GONE), causing the view renderization needed to animate it.

That's not an easy one. Till you got a real answer : The animation start is triggered by onNetworkEvent. As we don't know the rest of the code, you should look there, try to change onNetworkEvent by an other event that you can easily identify, just to debug if the rest of the code is ok or if it's just the trigger that is responsible for it.

May be it will help someone, because previous answers not helped me.

My animation was changing height of view (from 0 to it's real height and back) on click - expand and collapse animations.

Nothing worked until i added listener and set visibility to GONE, when animation ends:

collapseAnim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

And when expand just set it to VISIBLE before animation:

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