On Honeycomb and later, you can add an OnLayoutChangeListener
to the view.
Prior to Honeycomb, you would have to use an OnGlobalLayoutListener
. This is a bit trickier because it gets called for the entire layout, not just the view you specified, so typically you would register it, then unregister it the first time it is called.
linearLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
linearLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// do the rest of your stuff here
}
});
Until there is a measure/layout pass, the reported size of the view will be zero.