How may I know how many child views may I programmatically add to a horizontal oriented LinearLayout?
I tried something like this:
for (int i = 0; i < listSize; i++) {
View childView = getChildView(parentView); // method that returns an inflated View from a xml layout
if (parentView.getChildCount() > 0 && childView.getWidth() > parentView.getWidth() - parentView.getPaddingRight() - parentView
.getChildAt(parentView.getChildCount()-1)
.getRight()) {
break;
}
parentView.addView(childView);
}
but it seems like it doesn't work. Any ideas are much appreciated.
EDIT: It adds only one child to that LinearLayout, although it clearly looks like that should be enough space to add at least one more. After logging those variables used in the 'if' condition, it looks like parent.getWidth, and parentView.getChildAt(...).getRight() returns 0.