Is there a way to listen for animation end in AnimatedVectorDrawables

前端 未结 4 842
一向
一向 2020-12-31 00:35

I have created an AnimatedVectorDrawable, it works pretty well, now I am looking for a way to change the animation or hide the view after it finishes. I was hoping there was

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 01:23

    It is strange that there is no direct API for getting this. I suppose a workaround that doesn't involve overrides would just be simply to find the animation in your set of animations that takes the most amount of time, then post a delayed runnable to hide the view.

    int longestAnimationTime = 500; //miliseconds, defined in XML possibly?
    drawable.start();
    drawableView.postDelayed(new Runnable() {
    
            @Override
            public void run() {
                drawableView.setVisibility(View.GONE);
            }
    }, longestAnimationTime);
    

    Downside is that it involves hard coding your longest animation time, but as long as you are referencing the same constant value both in the animation XML and in code, it would work correctly, no overrides needed.

提交回复
热议问题