ImageView 只旋转一次 (Android)
ImageView rotates only once (Android)
我有一个刷新按钮,我想旋转它直到获取地理位置。
问题是只转一圈就停了
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 构造函数的签名
旋转动画(float fromDegrees,float toDegrees,float pivotX,float pivotY)
如果需要根据您的要求修复 pivotX、pivotY。即如果你想从中心旋转而不是使用 (width/2, height/2) for (pivotX, pivotY).
我有一个刷新按钮,我想旋转它直到获取地理位置。 问题是只转一圈就停了
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 构造函数的签名 旋转动画(float fromDegrees,float toDegrees,float pivotX,float pivotY)
如果需要根据您的要求修复 pivotX、pivotY。即如果你想从中心旋转而不是使用 (width/2, height/2) for (pivotX, pivotY).