使用 RotateAnimation 在 Android 中围绕固定点旋转 ImageView
我想围绕一个固定点连续旋转图像 360 度。我已经看到了一些例子,例如:
RotateAnimation anim = new RotateAnimation(0, 360,150,150);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(2000);
[imageview].startAnimation(anim);
这确实会旋转图像,但它是在弧形/圆形路径上旋转的。 IE。图像以圆周运动移动/旋转,但并未固定在其起始位置。
我基本上想要的是模仿风车手臂的旋转。
有什么想法吗?
I'd like to rotate an image 360 degrees continuously around a fixed point. I've seen a few examples already such as:
RotateAnimation anim = new RotateAnimation(0, 360,150,150);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(2000);
[imageview].startAnimation(anim);
This does rotate the image, but it does so on an arc/circular path. Ie. the image is moving/rotating in a circular motion but isn't staying fixed at it's starting location.
What I basically want is to mimic the rotation of a WindMill's arms.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用此代码,
这将使您的图像在其固定位置旋转,即围绕其自身旋转
Use this code
this will rotate your image on its fixed position, i.e. around itself
好的,经过一些调整后我完美地工作了。正如 Macarse 所说,它确实涉及 ImageView 周围的填充。
要解决此问题,您所需要做的就是将
ImageView
放入RelativeLayout
中:Ok so I got this working perfectly after some tweaking. Like Macarse said, it did involve the padding around the
ImageView
.To fix this issue, all you have to do is put your
ImageView
inside aRelativeLayout
:我会说将 imageview.. 的枢轴点设置为 x = imgView.getWidth()/2 和 y = imgView.getHeight()/2
i will say set the pivot point of imageview.. to the x = imgView.getWidth()/2, and y = imgView.getHeight()/2