Re: [android-developers] Ok to measure widgets before display?
The correct thing to do is write your own layout manager that does the measurement and layout at the appropriate places.
On Tue, Nov 10, 2009 at 6:00 AM, Mark Wyszomierski <markww@gmail.com> wrote:
Hi,
I need to find out how wide a button with particular text will be
before displaying a layout. Is this a valid way of doing it behind the
scenes?:
LinearLayout lll = new LinearLayout(getContext());
Button btn = new Button());
btn.setText("wonderful!");
lll.addView(tvs);
lll.measure(1000, 1000);
lll.layout(0, 0, 1000, 1000);
int width = btn.getWidth();
I have other UI components that have to all be the same width in my
layout, as whatever this one button is (the other widgets are placed
all over the UI and I can't use any other layout methods to force them
to be the same size).
So I thought I could create this temporary layout, add my fake button,
measure it to get its width, then use that value on all other
controls. Right now I'm doing the same thing only in onWindowFocus(),
but this happens after the layout has been displayed once, which I'd
like to avoid,
Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Dianne Hackborn
Android framework engineer
hackbod@android.com
Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home