Did it! Thanks Romain! :)

For other people having the same trouble, the trick is to use the
onWindowFocusChanged(boolean hasWindowFocus) class like in this
example :

public void onWindowFocusChanged(boolean hasWindowFocus) {

int maxButton; // I save the biggest button width in this variable

Button testButton = (Button)findViewById(R.id.test); // button 1
Button testButton2 = (Button)findViewById(R.id.test2); // button 2
Button testButton3 = (Button)findViewById(R.id.test3); // button 3

maxButton=testButton.getWidth(); // I put button 1's width into
maxButton
if(testButton2.getWidth() > maxButton) { // If button 2's width is
bigger
maxButton = testButton2.getWidth(); // maxButton gets button 2's width
testButton3.setText("Button 2 is bigger than button 1!");
}

else
testButton3.setText("Button 1 is bigger than button 2!");

}


On Sep 27, 12:12 am, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> You can use a ViewTreeObserver. Look at the documentation of the
> android.view.View class for more information.
>
> On Sep 26, 2008 10:42 AM, "erkenbrandroid" <[EMAIL PROTECTED]> wrote:
>
> Hello everyone!
>
> I need a bit of help for an app I am trying to develop.
>
> I've got a main screen with a couple of buttons on it.
>
> What I would like to do is get the width of those buttons before they
> are actually drawn on the screen. Their width is variable, as theyr
> are defined as "wrap_content" in my main.xml
>
> I tried to get the buttons' width in the methods onCreate() and
> onStart() but all I get is a 0 measure, obviously because their width
> can't be measured yet.
>
> Do you know a way to do that?
>
> this is an example of the code at the moment :
>
> public void onCreate(Bundle savedInstanceState) {
>
> int maxButton; // I save the biggest button width in this variable
>
> Button testButton = (Button)findViewById(R.id.test); // button 1
> Button testButton2 = (Button)findViewById(R.id.test2); // button 2
> Button testButton3 = (Button)findViewById(R.id.test3); // button 3
>
> maxButton=testButton.getWidth(); // I put button 1's width into
> maxButton
> if(testButton2.getWidth() > maxButton) { // If button 2's width is
> bigger
> maxButton = testButton2.getWidth(); // maxButton gets button 2's width
> testButton3.setText("Button 2 is bigger than button 1!");}
>
> else
> testButton3.setText("Button 1 is bigger than button 2!");
>
> }
>
> Thanks a lot,
> Erken
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to