如何为旋转动画设置动态枢轴
How to set dynamic pivots for rotate animation
我有一张图片。我需要它以其左下角为中心旋转一个小角度。当我点击屏幕时,此动画有效。图像出现在那里并旋转。但对于不同的位置,枢轴是不变的。我如何以编程方式为每个案例动态设置数据透视表?
?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)
我有一张图片。我需要它以其左下角为中心旋转一个小角度。当我点击屏幕时,此动画有效。图像出现在那里并旋转。但对于不同的位置,枢轴是不变的。我如何以编程方式为每个案例动态设置数据透视表?
?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)