我想在固定点周围连续旋转360度。我已经看过一些例子:
RotateAnimation anim = new RotateAnimation(0, 360,150,150);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(2000);
[imageview].startAnimation(anim);
这会旋转图像,但它会在弧形/圆形路径上旋转。 IE浏览器。图像以圆周运动方式移动/旋转,但不会固定在它的起始位置。
我基本上想要的是模仿WindMill手臂的旋转。
有什么想法吗?
答案 0 :(得分:7)
使用此代码
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setInterpolator(new LinearInterpolator());
rotateAnimation1.setDuration(duration);
rotateAnimation1.setRepeatCount(0);
img.startAnimation(rotateAnimation1);
这会将图像旋转到固定位置,即自身周围
答案 1 :(得分:0)
可能是由填充引起的。请检查此similar question。
答案 2 :(得分:0)
好的,所以我经过一些调整后得到了完美的效果。就像Macarse所说,它确实涉及ImageView
周围的填充。
要解决此问题,您只需将ImageView
置于RelativeLayout
内:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/imageview"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/image"
/>
</RelativeLayout>
答案 3 :(得分:-1)
我会说将imageview的轴心点设置为x = imgView.getWidth()/ 2,y = imgView.getHeight()/ 2