On Monday, January 24, 2011 7:51:27 PM UTC, Kumar Bibek wrote: Normally, the layout should be ready when the onCreate method is over. >
That's not been my experience. Across a number of my apps, sizes of various elements are reported as 0 in onCreate. Kind of a pain. It's not been hard to work around, but I'd be interested to know if there's a better way. Or when you say "when the onCreate method is over", do you mean AFTER onCreate, in some later event? Which one? String > Do you have any problems with that? > > On Jan 24, 11:40 am, MikeO <[email protected]> wrote: > > How can I get notified when the layout is fully calculated? The short > > answer is to attached a listener for a callback when the layout is > > calculated. Here's what it looks like. > > > > @Override > > public void onCreate(Bundle savedInstanceState) > > { > > super.onCreate(savedInstanceState); > > RelativeLayout vMain = (RelativeLayout) > > this.getLayoutInflater().inflate(R.layout.main, null); > > vMain.getViewTreeObserver().addOnGlobalLayoutListener( > > new ViewTreeObserver.OnGlobalLayoutListener() { > > public void onGlobalLayout() { > > DisplayLayoutDimensions(); > > } > > }); > > setContentView(vMain); > > > > } > > > > public void DisplayLayoutDimensions() > > { > > StringWriter sw = new StringWriter(1000); > > PrintWriter out = new PrintWriter(sw); > > TextView t = (TextView) findViewById(R.id.textview); > > ImageView img = (ImageView) findViewById(R.id.hp67); > > out.printf("\nImage Drawable\n"); > > out.printf("ImageView Height dp: %d\n", img.getHeight()); > > out.printf("ImageView Measured Height dp: %\n", > > img.getMeasuredHeight()); > > t.setText(sw.toString()); > > > > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

