In my applications, I often rely on custom build views, such as in the following example.
I'm using Android Studio so I'm not sure this answer will apply to your case.
I think you could override onDraw method in the custom view, like this exemple keeping the aspect ratio of an inner image:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// TODO: consider storing these as member variables to reduce
// allocations per draw cycle.
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
int paddingRight = getPaddingRight();
int paddingBottom = getPaddingBottom();
int w = getWidth() - paddingLeft - paddingRight;
int h = getHeight() - paddingTop - paddingBottom;
w = w
This method runs both in the emulator and the designer.
It runs as well for any event that redraws the view (onSizeChanged, onLayout, etc...)