8
<ImageView
      android:id="@+id/imageView1"
      android:layout_width="300dp"
      android:layout_height="300dp"
      android:src="@drawable/zaid1"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true" />

我在活动中间有一个图像视图,我将如何使它无休止地旋转 360 度?

4

2 回答 2

25

尝试使用RotateAnimation

RotateAnimation rotateAnimation = new RotateAnimation(0, 360f,
    Animation.RELATIVE_TO_SELF, 0.5f,
    Animation.RELATIVE_TO_SELF, 0.5f);

rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(500);
rotateAnimation.setRepeatCount(Animation.INFINITE);

findViewById(R.id.imageView1).startAnimation(rotateAnimation);
于 2015-09-17T22:57:25.750 回答
2

或者 XML 方式。在您的 res 文件夹中创建“anim”文件夹。创建一个xml文件,随意命名。你将在这里定义你的动画。

在xml文件里面放:

<?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android" 
        android:fromDegrees="0"
        android:toDegrees="359"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="6000"
        android:interpolator="@android:anim/linear_interpolator"
        android:repeatCount="infinite"/>

现在您只需加载动画:

Animation rotation = AnimationUtils.loadAnimation(this, R.anim.your_xml_name);

然后启动它:

findViewById(R.id.imageView1).startAnimation(rotation);
于 2015-09-18T00:32:08.887 回答