图像drawable旋转不工作android?

时间:2016-01-21 13:02:49

标签: android imageicon image-rotation

我需要使用xml属性从drawable旋转图像图标我已经尝试过不同的方式,但似乎没有任何工作。

  

机器人:旋转= “90”

     

机器人:fromDegrees = “0”

     

机器人:toDegrees = “360”

     

机器人:pivotX = “50%”

     

机器人:pivotY = “50%”

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

我做错了什么?

2 个答案:

答案 0 :(得分:1)

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

<强> 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"

答案 1 :(得分:1)

这应该在编译后起作用:

android:rotation="90"

您无法在预览中看到它,但在模拟器上安装后它才能正常工作。

如果您遇到任何问题,请使用Java:

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