2

I need to rotate image icon from drawable using xml attributes i have tried it in different way but nothing seems working.

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

What I'm doing wrong ?

Stella
  • 1,817
  • 6
  • 30
  • 55

2 Answers2

1

Create a drawable file like this..

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>

define this file drawable folder

In ImageView, use: android:background="@drawable/rotate"

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
Ram Prakash Bhat
  • 1,308
  • 12
  • 21
1

This should work after compiling:

android:rotation="90"

You can't see it on your Preview but it's working after installing on the emulator.

If you had any problems, use Java:

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

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108