0

I need to know correct widths, heights and positions of some of the views in my Activity ASAP after onResume. Where can I place this code in my Activity?

Andrey Novikov
  • 5,563
  • 5
  • 30
  • 51

1 Answers1

4

Oddly, I get to reuse an answer the same day I make it:

You could set a global layout listener on the view tree in your onResume() and do your diddling in there.

final ViewTreeObserver vto = myView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

    public void onGlobalLayout() {
        // do layout tweaking based on measurements

        // remove the listener... or we'll be doing this a lot.
        vto.removeGlobalOnLayoutListener(this);
    }
}
Brian Dupuis
  • 8,136
  • 3
  • 25
  • 29