Rotate ImageView for its bottom right corner Android

Viewed 504

i want to rotate my image view 45 degree from its bottom right corner please tell me how i can 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 was added
        />

but this code rotate my image from its center point so please tell me how i rotate my image from bottom right corner.

1 Answers

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.

Related