android:关于属性动画的原点位移

好久不写程序,这次写掼蛋游戏,竟然怎么也记不得怎么写基于原点的位移动画了。

总是想着通过getX,getY去找原点坐标,而这个坐标本身有延迟,很不稳定。

今天无意翻看从前写的代码,发现在移动属性前,加个“+”、“-”符号就行。

也就是说:在ObjectAnimator.ofFloat()方法中,value如意直接写,它会理解成坐标,如果加上+、-号,它会理解成移动的距离。

这里还是记录一下,老了,总忘。

@SuppressLint("Recycle") ObjectAnimator tranXRight = ObjectAnimator.ofFloat(binding.rightPhoto, "translationX", +60);
@SuppressLint("Recycle") ObjectAnimator tranYRight = ObjectAnimator.ofFloat(binding.rightPhoto, "translationY", -120);

 

posted @ 2024-02-08 15:30  风肖肖(肖遥)  阅读(7)  评论(0编辑  收藏  举报