我正在使用以下代码来旋转 ImageView
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="500"
android:repeatCount="infinite"
android:pivotX="50%"
android:pivotY="50%"
>
</rotate>
</set>
Animation rotate1 = AnimationUtils.loadAnimation(this, R.anim.rotate_picture); rotate.startAnimation(rotate1);
我使用的布局是:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/loader"
android:layout_centerInParent="true"
android:id="@+id/rotate"
/>
</RelativeLayout>
但它是停止 500 毫秒并重新启动。但我需要连续旋转图像。中途不 parking 。我该怎么做?
最佳答案
//custom_anim.xml
<?xml version="1.0" encoding="utf-8" ?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000" />
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000">
</alpha>
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale=".1"
android:fromYScale=".1"
android:toXScale="1.0"
android:toYScale="1.0"
android:duration="2000" />
</set>
//Oncreate
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
imgageview.startAnimation(rotateimage);
rotateimage.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
AnimateandSlideShow();
}
});
//function
private void AnimateandSlideShow() {
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
imgageview.startAnimation(rotateimage);
rotateimage.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
AnimateandSlideShow();
}
});
}
关于android - 在 Android 中连续旋转 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9630801/