0

我正在使用此 xml 代码将 imageVeiw 旋转 180 度:

<ImageView
    android:id="@+id/keyP2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btn4"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="true"
    android:rotation="180"
    android:maxWidth="125dp"
    android:scaleType="fitCenter"
    android:src="@drawable/image0_key" />

这适用于 android api 版本 11 及更高版本,但android:rotation="180"不支持低于 api 11。如何将 imageView 旋转 180 度以低于 11?

4

2 回答 2

5

试试这个。它对我有用。

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator" >

  <rotate
      android:duration="2000"
      android:fromDegrees="0"
      android:pivotX="50%"
      android:pivotY="50%"
      android:toDegrees="360" >
  </rotate>

</set>

将此文件保存在名为“anim”的文件夹下的资源中。

res/anim/rotate.xml

在你的活动中。添加此代码。

    Animation sampleFadeAnimation = AnimationUtils.loadAnimation(PreviewImageActivity.this,R.anim.rotate);
    sampleFadeAnimation.setRepeatCount(1);
    yourImageView.startAnimation(sampleFadeAnimation);

做一些研究,你会得到很多属性来根据你的意愿改进这个旋转动画。

谢谢...

于 2013-07-23T05:37:14.233 回答
0

您可能想尝试通过扩展 Animation. 在我的头顶上是这样的:

RotateAnimation rotateAnim = new RotateAnimation(0f, 350f, 15f, 15f);
rotateAnim.setInterpolator(new LinearInterpolator());
rotateAnim.setRepeatCount(Animation.INFINITE);
rotateAnim.setDuration(700);

// Start the animation
final ImageView imgView = (ImageView) findViewById(R.id.YOUR_ID);
imgView.startAnimation(rotateAnim);

// Stop when necessary
imgView.setAnimation(null);

虽然我不完全确定 RotateAnimation 在 11 之前是否受支持。但是您应该能够以编程方式进行操作。

编辑:有关其他选项,请参阅Android Rotatable ImageView

于 2013-07-22T23:59:24.913 回答