This is I think the first time in my whole programmer's life that I ask something. Before I was always able to find the solution by myself or on internet. But here, I give up ...
About the tittle, of course ViewGroup is abstract, but the idea is to have a element that can handle many other child elements in a "list".
Here is the problem. Imagine you have your ViewGroup (or other descendant class), and you want to add as much as possible elements in this space without having a scroll bar or some elements truncated. The elements will be one under the other. For exemple if 4.65 elements can fit in this free space, then only 4 will be added. Because adding a 5th will result in a truncated element, because there is simply not enough space to add 5 elements.
I tried some things like calculating the space available in the (in this case) LinearLayour, and adding a "pilot" element to measure it, and then to know how many other I could add. But this is not working. The height returned by the "pilot" element is incorrect.
I tried so many thing, that I can't explain everything here, but if you have some ideas on how to do it, just say. It's been 3 days I'm on this problem, it makes me crazy.
Finally I found the solution. I can't really explain it here, because I use custom home made components, but I was able to fin the source of the problem.
While creating the simplified class to demonstrate the problem, I found that in fact everything was working correctly. So I compared the simplified class with my project's one, and modified them until they were almost the same.
I found the source of the problem, even if I don't understand why there is a problem. In fact, if you set the textsize via a constant before doing the calculation methods (pilot element, space calculation and so on), it works perfectly. If you modify the size by calling an accessor(setSize) even prior to do the calculations to know how many elements you can add, it won't work the same.
That's really weird, because I modify the textSize before doing the calculations. It should work the same. Anyway. I found a trick using Threads/Handlers that solves my problem. It was difficult to find the problem, but impossible to understand why it happens.