2011-03-06 75 views
4

我想旋转一个固定点360度的图像。我见过几个例子已经如:使用RotateAnimation在Android中围绕固定点旋转ImageView

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

好吧,所以经过一些调整后我的工作完美无缺。像Macarse说的那样,它确实涉及围绕ImageView的填充。

要解决这个问题,所有你需要做的就是把你的ImageViewRelativeLayout

<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> 
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); 

这将在其固定位置,即图像旋转本身周围

+0

我需要旋转手柄上下像我拖动手柄向上和向下 – 2017-02-15 05:12:59

+0

akhir kehna kya chahte ho? – 2017-02-27 11:53:47

-1

我将imageview的的枢转点..说设定为X = imgView.getWidth()/ 2,并且y = imgView.getHeight()/ 2