Android中的布局参数动画性能低下

目前我使用下面的代码来动画对象的宽度:

val animation = ValueAnimator.ofInt(layoutParams.width, value) .setDuration(duration) animation.interpolator = interpolator ?: LinearInterpolator() animation.start() animation.addUpdateListener { val animatedValue = it.animatedValue as Int layoutParams.width = animatedValue requestLayout() } animation.addListener(object: Animator.AnimatorListener { override fun onAnimationRepeat(p0: Animator?) {} override fun onAnimationEnd(p0: Animator?) { endHandler?.invoke() } override fun onAnimationCancel(p0: Animator?) {} override fun onAnimationStart(p0: Animator?) {} }) 

但是,即使在简单的布局上,动画也是非常滞后的。 有没有什么办法来改善layoutParams更改动画的性能?

我在克拉科夫的“办公时间”在GDD 2017上问过这个问题,他们告诉我看看Nick Butcher的App – > Plaid.io。 如果你对Android的动画有兴趣,绝对值得一看。

链接在这里:

https://github.com/nickbutcher/plaid

我们做到了,我们看到他经常使用

 animation.willChangeBounds = true 

并且用laggy动画<3解决了我们的问题

使用animation.setTarget(viewToAnimate)方法为目标视图设置动画效果。

我没有测试过,让我知道它的工作与否。

希望它有帮助。