【问题标题】:Image drawable rotation not working android?图像可绘制旋转不适用于android?
【发布时间】:2016-01-21 13:02:48
【问题描述】:

我需要使用 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" />

我做错了什么?

【问题讨论】:

    标签: android imageicon image-rotation


    【解决方案1】:

    这应该在编译后工作:

    android:rotation="90"
    

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

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

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

    【讨论】:

    • 以编程方式:)
    • 是的,有时以编程方式会做同样的事情,但功能更强大,就像这样:) 祝你好运
    【解决方案2】:

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

    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"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 2020-07-01
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多