I'm rotating a view containing an arrow in my app using the Matrix class. However, the arrow doesn't rotate around its c开发者_开发技巧enter but moves a bit horizontally and vertically when rotating. I've experimented with margins and padding but without success. Any hints much appreciated.
The setRotate method in Matrix defaults to the (0,0) point of the view, which is the top left corner. You can set the point you want to rotate around by using the setRotate(float angle, float px, float py) method in the Matrix class. The x and y parameters are local to the view so you can get the center point from the bounds of the view or from getWidth and getHeight.
I think the translation works as you expect. It is the way you draw the resulting image which leads to imprecision. I have just answered a similar question Android problem with Image Rotate and Matrix
精彩评论