I have a simple problem. I'm extending ViewGroup, and I want to align buttons to the right side of the screen from top-to-bottom. Problem is, nothing shows up on my screen. I've confirmed it's not a problem with anything else, only my onLayout() overriden method. Could you help me out?
Code in question:
final int count = getChildCount();
int curWidth, curHeight, curLeft, curTop;
//get the available size of child view
int childLeft = this.getPaddingLeft();
int childTop = this.getPaddingTop();
int childRight = this.getMeasuredWidth() - this.getPaddingRight();
int childBottom = this.getMeasuredHeight() - this.getPaddingBottom();
int childWidth = childRight - childLeft;
int childHeight = childBottom - childTop;
curTop = childTop;
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
//Get the maximum size of the child
child.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST));
curWidth = child.getMeasuredWidth();
curHeight = child.getMeasuredHeight();
child.layout(getMeasuredWidth() - getPaddingRight() - curWidth,
curTop, getMeasuredWidth() - getPaddingRight(), curTop - curHeight);
curTop -= childHeight;
}
I've added a few LOG statements to my code, and what I have is frankly infuriating.
07-11 14:46:46.321 32172-32172/milespeele.canvas D/Miles﹕ LEFT: 912
07-11 14:46:46.322 32172-32172/milespeele.canvas D/Miles﹕ TOP: 1008
07-11 14:46:46.322 32172-32172/milespeele.canvas D/Miles﹕ RIGHT: 1080
07-11 14:46:46.322 32172-32172/milespeele.canvas D/Miles﹕ BOTTOM: 1008
These are all valid coordinates (for one button) given the dimensions of my phone's creen, but no buttons are appearing.