我有一个刷新按钮,我想旋转它,直到获取地理位置。问题是它只旋转一个周期就停止了。
refresh_button_rotate.xml:
<?xml version="1.0" encoding="utf-8"?>
<set>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
</set>
主要片段:
refreshGeo.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
Animation rotation = AnimationUtils.loadAnimation( mContext, R.anim.refresh_button_rotate );
rotation.setRepeatCount(Animation.INFINITE);
rotation.setRepeatMode(Animation.RESTART);
refreshGeo.startAnimation(rotation);
我还尝试了另一种方法:
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
final ImageView splash = refreshGeo;
splash.startAnimation(anim);
它确实不停地旋转图像,但它会从视图的左上角旋转图像。。
您使用的RotateAnimation构造函数的签名旋转动画(从度浮动,浮动到度,浮动轴X,浮动轴Y)
如果需要固定枢轴X,请根据您的要求固定枢轴Y。即,如果要从中心旋转,则使用(宽度/2,高度/2)作为(枢轴X,枢轴Y)。