图片可绘制旋转不起作用 android?

Image drawable rotation not working android?

我需要使用 xml 属性从可绘制对象中旋转图像图标 我已经尝试过不同的方法,但似乎没有任何效果。

android:rotation="90"

android:fromDegrees="0"

android:toDegrees="360"

android:pivotX="50%"

android:pivotY="50%"

 <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:rotation="90"
            android:src="@drawable/ic_arrow_collapse" />

我做错了什么?

像这样创建一个可绘制文件..

rotate.xml:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
        android:fromDegrees="90"
        android:toDegrees="90"
        android:pivotX="50%"
        android:pivotY="50%"
        android:drawable="@drawable/ic_arrow_collapse">
</rotate>

定义此文件可绘制文件夹

ImageView中,使用:android:background="@drawable/rotate"

这应该在编译后工作:

android:rotation="90"

您在预览版中看不到它,但在模拟器上安装后它可以正常工作。

如果有任何问题,请使用 Java:

Android: Rotate image in ImageView by 90degrees but without delay