如何设置旋转动画的动态轴

我有一个形象。 我需要它在左下角旋转一个小角度。 当我点击屏幕时,这个动画工作。 图像出现在那里并旋转。 但是对于不同的位置,这个支点是不变的。 我怎样才能以编程方式动态设置每个案例的枢纽?

?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <rotate android:duration="500" android:interpolator="@android:anim/linear_interpolator" android:pivotY="100%" android:pivotX="0%" android:repeatCount="0" android:toDegrees="10"/> </set> 

有没有什么方法可以给我们getX()getY()的值赋予枢轴值?

得到了答案。 做这样做

 var screenH=Resources.getSystem().getDisplayMetrics().heightPixels var screenH=Resources.getSystem().getDisplayMetrics().widthPixels var x= ("x value of your pivot)/screenW var y= ("y value of your pivot)/screenH var rotateAnim=RotateAnimation(0.0f , 20.0f , Animation.RELATIVE_TO_PARENT , x , Animation.RELATIVE_TO_PARENT , y) rotateAnim.setDuration(1000) rotateAnim.setFillAfter(true) view.startAnimation(rotateAnim)