What you ask for cannot be done simply by creating rules. You need to do extra work for such alignment.
1) use addRule to align the parent left and align the parent top, then set the left and top margins to align the image to any position where you want 100, 100 or 200, 50, etc., after which you can resize images without repositioning.
2) if you save the image according to CENTER_IN_PARENT, then the image size is a bit typical. you need to enlarge the left and top pad to fit the larger size to align the image in the center.
Suppose the image size is 100x100 and the new size is 150x150
Now you need to set the layout parameters in width x height to 200x200 and set the left and top fill of the image to 50.
I hope its clear
source share