Android - reacting after initial layout
<p>This question has been asked several times in various forms but I haven't found a definitive answer.</p>

<p>I need to be able to get dimensions and positions of descendant <code>Views</code> after the initial layout of a container (a <code>contentView</code>).  The dimensions required in this case are of a View(Group) that is not predictable - might have multiple lines of text, minimum height to accommodate decoration, etc.  I don't want to do it every on every layout pass (<code>onLayout</code>).  The measurement I need is a from a deeply nested child, so overriding the <code>onLayout</code>/<code>onMeasure</code> of each container in between seems a poor choice.  I'm not going to do anything that'll cause a loop (trigger-event-during-event).</p>

<p>Romain Guy hinted once that we could just <code>.post</code> a <code>Runnable</code> in the constructor of a <code>View</code> (which AFAIK would be in the UI thread).  This seems to work on most devices (on 3 of the 4 I have personally), but fails on Nexus S.  Looks like Nexus S doesn't have dimensions for everything until it's done one pass per child, and does not have the correct dimensions when the <code>post</code>ed <code>Runnable</code>'s <code>run</code> method is invoked.  I tried counting layout passes (in <code>onLayout</code>) and comparing to <code>getChildCount</code>, which again works on 3 out of 4, but a different 3 (fails on Droid Razr, which seems to do just one pass - and get all measurements - regardless of the number of children).  I tried various permutations of the above (posting normally; posting to a <code>Handler</code>; casting <code>getContext()</code> to an <code>Activity</code> and calling <code>runOnUiThread</code>...  same results for all).</p>

<p>I ended up using a horrible shameful no-good hack, by checking the height of the target group against its parent's height - if it's different, it means it's been laid out.  Obviously, not the best approach - but the only one that seems to work reliably between various devices and implementations.  I know there's no built-in event or callback we can use, but is there a better way?</p>

<p>TYIA</p>

<p><strong>/EDIT</strong> The bottom line for me I guess is that the Nexus S does not wait until after layout has completed when <code>.posting()</code> a <code>Runnable</code>, as is the case on all other devices I've tested, and as suggested by Romain Guy and others.  I have not found a good workaround.  Is there one?</p>
