I have following widget in my app and it contains an
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
When your widget is added, it will be stretched to occupy the minimum number of cells, horizontally and vertically, required to satisfy its minWidth and minHeight constraints.
Each device has a grid on its home screen that widgets are forcefully aligned with. You can even see on some devices that the aspect ratio of the grid cells change when rotating between portrait and landscape.
The docs at the link above have some advice for how to specify sizes for your widgets. Some of the information there might help you.
I would recommend that if you are only showing the
ImageView, instead of using a
RelativeLayout, use a
FrameLayout with a gravity of
center and a transparent background. That way the
FrameLayout might get stretched but your
ImageView should stay square.
Even better, you might not need a
ViewGroup subclass at all. Just have the
ImageView as your top level component and use a scale type of
FIT_CENTER. Then your bitmap should square up inside the
ImageView. (Oh, and don't specify a background color for the
ImageView, just do the background color in the bitmap.)