I've been trying to find a solution to this, but perhaps I'm not understanding how the "onMeasure()" method works so well in Android!
This is the first time I've made custom views "dynamic" in Android, so I learned that you need to override the "onMeasure()" method in order to resize your view depending upon how large the screen is. I would like the my view to be half the width of the screen, plus a little extra (this number is arbitrary, as long as its relatively small, between 3 and 5), so I wrote this code for the onMeasure method:
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int halfWidth = (MeasureSpec.getSize(widthMeasureSpec) / 2) - 5;
this.setMeasuredDimension((int) halfWidth, (int) halfWidth);
}
I'm sure this a terrible way of going about things because everywhere I've found online has so much more code than I do while trying to accomplish something similar!
When I place these views next to each other in the XML, this first view is correctly sized (it is indeed half the size of the width minus a little more), but the second view is much smaller, probably half the size of the width of the last view minus a little more! (I would post a picture of it but unfortunately I don't have enough reputation to do so...)
What should occur is the two boxes should be the same size, no matter where in the XML I place them. They should all be one-half the size of the width of the screen, minus a little extra.
I know it has something to do with how I'm using "setMeasuredDimension()", but I don't know what it is. I really hope someone could clarify things a bit for me! Thanks! :)