我想动态旋转图像(不是通过 XML 代码)。我正在使用此代码来旋转图像:
public void rotateAnimation(){
// Create an animation instance
Animation an = new RotateAnimation(30, 360);
// Set the animation's parameters
an.setDuration(2000); // duration in ms
an.setRepeatCount(0); // -1 = infinite repeated
an.setRepeatMode(Animation.REVERSE); // reverses each repeat
an.setFillAfter(true); // keep rotation after animation
// Aply animation to image view
scanCircle.setAnimation(an);
}
使用这段代码,我的 ImageView 得到了旋转,但它不是在它的位置上而是在它的位置之外。我想要的是在它自己的位置旋转它。
那么,如何让它成为可能?
最佳答案
我认为定位 pivotx 和 pivotY 会有所帮助 http://developer.android.com/reference/android/view/animation/RotateAnimation.html#RotateAnimation%28float,%20float,%20float,%20float%29
RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)
假设你想从中间开始旋转
RotateAnimation(30, 360, totalWidth/2, totalHeight/2)
关于android - 如何在其位置动态旋转图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10278288/