4

I want to rotate my image view 45 degree from its bottom right corner please suggest me how to do that

I am trying to add rotation in imageview like this

 <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/poker_table"
        android:scaleType="fitXY"
        android:id="@+id/poker_table"
        android:rotation="45" //this line I added
        />

but the above code rotating my image from its center point. So please suggest any solution to rotate image from bottom right corner.

Hemant Prajapat
  • 125
  • 2
  • 14

1 Answers1

2

If you know the size of the View, you can use a pair of xml atttributes to set a pivot point for rotating or scaling a View: android:transformPivotX and android:transformPivotY

If we assume the View has a size of 100dp x 100dp:

android:transformPivotX="100dp"
android:transformPivotY="100dp"

Other possible units are sp, px, in, mm... but unfortunately match_parent will not work, and neither will 100%.

If you don't know the size of the View at compile time, your only option is to set the pivot point programmatically (using setPivotX() and setPivotY()) after determining its actual size.

Bö macht Blau
  • 12,820
  • 5
  • 40
  • 61
  • when i rotate my image then my image pixels is disturbing can you please also explain me how i can remove this error – Hemant Prajapat May 13 '20 at 06:15
  • @HemantPrajapat - I think it's better if you ask a new question about this new issue (ideally with some screenshots since I'm not sure what exactly is wrong with your View). One reason for a new question is that we try to keep questions small: solve one problem at a time, not mentor throughout an entire project. This is good for future readers in a similar situation who search for answers which take them one step further (even if their project is quite different from yours). On the other hand you'll reach more people and so increase your chances of getting good advice for each of your issues. – Bö macht Blau May 13 '20 at 18:15