问题
It's possible to scale a RectF object of by an arbitrary factor in each direction? In practice i would resize of 2 factor a RectF (if RectF is 200X200 i would that he becomes 100x100)
回答1:
Try something like this:
private void scale(RectF rect, float factor){
float diffHorizontal = (rect.right-rect.left) * (factor-1f);
float diffVertical = (rect.bottom-rect.top) * (factor-1f);
rect.top -= diffVertical/2f;
rect.bottom += diffVertical/2f;
rect.left -= diffHorizontal/2f;
rect.right += diffHorizontal/2f;
}
This is done without testing but I think it should work. This should keep the center in the same place and expand outward. All sides will be twice as big.
来源:https://stackoverflow.com/questions/21779482/scale-rectf-object-in-each-direction