How to rotate the imageview with the central point?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to rotate the imageview with the central point?

Postby twsc » Mon Oct 05, 2009 4:11 pm

Dear All,

I know how to rotate the imageview by using matrix component.

I hope to roate the image file with fixing the central point in the same x/y position.

The central point means the black point in the attached image file.

But I use the rotate function, the rotated image is positioned by the layout_marginTop. So the circle doesn't look roate in the same position.

Does anyone know how to control rotating the imageview with the central point of this image file? Thanks very much:)



========================

float scaleWidth=(float) width;
float scaleHeight=(float) height;

Matrix matrix=new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.setRotate(20); //rotate 20 degrees

Bitmap resizedBMP=Bitmap.createBitmap(sourceBMP,0,0,width,height,matrix,true);
BitmapDrawable newDrawable=new BitmapDrawable(resizedBMP);

imageview_1.setImageDrawable(newDrawable);

========================

xml file:

<ImageView
android:id="@+id/iv_ring"
android:src="@drawable/buda_ring"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dip"
android:layout_marginTop="40dip"
android:layout_gravity="center"

/>
Attachments
rotate.png
rotate.png (9.92 KiB) Viewed 314 times
twsc
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Jan 28, 2009 2:23 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests