开发者

Rotating android view without affecting adjacent views

开发者 https://www.devze.com 2023-01-13 13:58 出处:网络
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'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

0

精彩评论

暂无评论...
验证码 换一张
取 消