Understanding measureWithLargestChild: Why breaks the layout?
I believe this is a bug in measure algorithm. There is following comment in LinearLayout.measureHorizontal(int, int)
method.
// Either expand children with weight to take up available space or
// shrink them if they extend beyond our current bounds
It says, the algorithm will shrink items with weight
if there is not enough space for them. As measureWithLargestChild
is set to true
, all items have the same width as the most left item. Now they all together don't fit into the parent's width anymore. Thus they will be shrank. If there were no bug, all items would have same width afterwards. But due to the bug, algorithm shrinks original (wrap_content) widths instead of widths calculated according to measureWithLargestChild
attribute. That's why two items on the right became smaller.