android - 在 Android 中连续旋转 ImageView

标签 android

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

相关文章:

android - 如何调整 DatePicker android 小部件的大小

android - 重命名日期选择器中的默认按钮(android)

android - 从 DialogFragment 打开 fragment (替换 Dialogs 父级)

java - 重写 Android Java 比较器类

android - 如何在 Android 屏幕闲置 5 分钟后在我的应用程序中设置 sleep ?

android - NFC Reader <-> Android通信和Android监听器

java - 如何删除 NavigationView 中可绘制对象的色调?

android - WebView 缓存会在应用程序运行之间持续存在吗?

android - 为什么 onStart 之后不调用 onRestoreInstanceState?

android - Android 应用程序中的云端点身份验证失败