日安。
如果可能的话,我将非常感谢你的帮助。
下面的代码完美地将imageView移动到x= 200和y= 100。在此移动之后,ImageView将围绕中心(0,0)位置旋转360度。
如何在X= 200和Y= 100 pLEASE时设置pivotX和pivotY值?
提前谢谢你。
保罗
public void onButtonClickRotate(View v) {
ObjectAnimator animatorX = ObjectAnimator.ofFloat(imageView, "translationX", 200f);
ObjectAnimator animatorY = ObjectAnimator.ofFloat(imageView, "translationY", 100f)
.setDuration(100);
ObjectAnimator rotation = ObjectAnimator.ofFloat(imageView,"rotation", 0f, 360f)
.setDuration(1000);
AnimatorSet set = new AnimatorSet();
set.playSequentially(animatorX, animatorY,rotation);
set.setDuration(2000);
set.start();
}
}发布于 2020-07-17 01:57:19
要在轴心点上旋转,请使用类似以下内容:
val imageView = view.findViewById<ImageView>(R.id.imageView)
val pivotY = ObjectAnimator.ofFloat(imageView, "pivotX", 30f)
val pivotX = ObjectAnimator.ofFloat(imageView, "pivotY", 70F)
val animR = ObjectAnimator.ofFloat(imageView, "rotation", 0F, 360F)
AnimatorSet().apply {
playTogether(animX, animY, animR)
start()
}只需设置所需的轴值即可。请务必在此处查看有关属性动画的指南,以了解更多细节和其他(可能更好)的方法:https://developer.android.com/guide/topics/graphics/prop-animation
发布于 2021-08-13 05:36:28
在我的用例中,以下方法起作用:
// set pivot point of the object
imageView.pivotX = pX
imageView.pivotY = pY
// start rotation animation. e.g. Y axes
oaY = ObjectAnimator.ofFloat(
imageView,
"rotationY",
0f, 360f, 0f)
oaY.start()https://stackoverflow.com/questions/62940081
复制相似问题