Android 带有旋转xml的ImageView不旋转
我使用以下代码Android 带有旋转xml的ImageView不旋转,android,xml,Android,Xml,我使用以下代码 <ImageView android:id="@+id/imgView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/animate"/> 但我的图像视图
<ImageView
android:id="@+id/imgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/animate"/>
但我的图像视图仍然没有旋转,
我见过很多例子,但都不管用。试试这个
<ImageView
android:id="@+id/imgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/animate"/>
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="359"
android:duration="1000" >
</rotate>
ImageView imgView=(ImageView)findViewById(R.id.imgView);
Animation rotation = AnimationUtils.loadAnimation(this, R.drawable.animate);
imgView.startAnimation(rotation);
ImageView imgView=(ImageView)findViewById(R.id.imgView);
动画旋转=AnimationUtils.loadAnimation(this,R.drawable.animate);
imgView.启动(旋转);
尝试在xml动画中执行此操作
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:interpolator="@android:anim/linear_interpolator"
android:duration="2500"<!-- put any duration you want -->
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
试试这个
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="4000"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
似乎有两种因素会导致此问题:
AnimationUtils.loadAnimation(this,R.drawable.animate)代码>animate.xml不应该是动画文件夹中的动画资源而不是可绘制的吗
你正在从90度旋转到90度。也许这只是什么都没做
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:interpolator="@android:anim/linear_interpolator"
android:duration="2500"<!-- put any duration you want -->
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="4000"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>