sweety wrote:
> I did something like this within my code:
> 
> public void test(){
>     TextView tv = (TextView)findViewById(R.id.text_view);
>     tv.setText("blablabla");
>     int width = tv.getWidth();
>     int height = tv.getHeight();
> }
> 
> When test() is called(I am sure it's not called in the view or its
> parent's constructor), Both width and height is zero!!! How can get
> the width and height? Because the text might be quite long and be
> ellipsized by TextView so Paint.measureText() and Paint.getTextBound()
> can't fulfill this need.

Most likely, your views are not yet laid out when you are calling 
test(). Either delay your call to test() until the views are laid out 
(e.g., onResume() might be late enough), or manually request a layout() 
of your root view.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com

Android Training on the Ranch! -- Mar 16-20, 2009
http://www.bignerdranch.com/schedule.shtml

--~--~---------~--~----~------------~-------~--~----~
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