java – ObjectAnimator vs TranslateAnimation

I'm just doing a simple project. I try to use translateanimation to show / hide the layout at the top of LinearLayout There is a flicker because when I call onanimationend(), the animation is not completed for 0.1 seconds

Example:

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

When I searched stack overflow, I found another way to do it Using objectanimator After using it, there is no view Gone, my animation is very good

What is the difference between translateanimation and objectanimator? Whether one of them is abandoned, they do the same thing, or there is a better time or another

This is a GitHub repository with 2 versions( https://github.com/charlesvigneault/AAA_Test1 )

thank you

Solution

The main difference is that if you use translate animation, the view of your animation does not really keep its original position on the screen, it just makes it look like it is moving Therefore, the view basically does not change its coordinates

Watch videos about watching animation: https://www.youtube.com/watch?v=_UWXqFBF86U

If you use objectanimator, the view does change its actual position

Translateanimation is not abandoned. You can still find it on lollipop, but for most cases, I can recommend a class called viewpropertyanimator, which many people don't seem to know. It may be the simplest and most direct way to view animation, and it can also save you a lot of code Here is an example:

retractableLayout.animate()
                .translationX(toX)
                .translationY(toY)
                .setDuration(duration)
                .setInterpolator(interpolator)
                .setStartDelay(startDelay);

You can also set up listeners, etc. be sure to check the available methods

Check out this very useful video:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>