gpt4 book ai didi

android - 在 Android 中连续旋转 ImageView

转载 作者:太空宇宙 更新时间:2023-11-03 11:20:12 24 4
gpt4 key购买 nike

我正在使用以下代码来旋转 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com