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 に答える