在不移动图像按钮的情况下旋转图像按钮

时间:2014-09-12 12:12:27

标签: android android-animation image-rotation

您好我正在使用ImageButton for android application

xml中的按钮看起来像这样:

[LEFT][LEFT]
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignTop="@+id/imageButton1"
android:layout_toRightOf="@+id/imageButton1"

我正在尝试使用此代码旋转它

RotateAnimation ra =new RotateAnimation(1000, 90);
ra.setFillAfter(true);
ra.setDuration(0);
prevBut.startAnimation(ra);

ImageButton会旋转 - 但旋转后会向左移动一点。

  

我感兴趣的是只旋转ImageButton而不移动它   那边可能吗?

2 个答案:

答案 0 :(得分:2)

TRY:

RotateAnimation ra = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
ra.setFillAfter(true);
ra.setDuration(0);
prevBut.startAnimation(ra);

<强>文档

public RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

从代码

构建RotateAnimation时使用的构造方法

参数:

fromDegrees :在动画开始时应用的旋转偏移量。

toDegrees :在动画结束时应用的旋转偏移量。

pivotXType :指定应如何解释pivotXValue。 Animation.ABSOLUTE,Animation.RELATIVE_TO_SELF或Animation.RELATIVE_TO_PARENT之一。

pivotXValue :对象旋转的点的X坐标,指定为绝对数字,其中0是左边缘。如果pivotXType为ABSOLUTE,则此值可以是绝对数,否则可以是百分比(其中1.0是100%)。

pivotYType :指定如何解释pivotYValue。 Animation.ABSOLUTE,Animation.RELATIVE_TO_SELF或Animation.RELATIVE_TO_PARENT之一。

pivotYValue :对象旋转点的Y坐标,指定为绝对数字,其中0是上边缘。如果pivotYType为ABSOLUTE,则此值可以是绝对数,否则可以是百分比(其中1.0是100%)。

答案 1 :(得分:0)

试试这个:

RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

ImageView image = findViewById(my image);
image.setAnimation(rotate);
rotate.setDuration(1000)
rotate.start();
相关问题