I have an Activity that makes use of a TextView that's defined in a
standard manner in layout/main.xml.

In my app, I want to get the dimensions of the drawing area in order
to decide how I am going to draw into it.

If my TextView is referenced as this.tv, I know I can get these
dimensions by calling this.tv.getWidth() and this.tv.getHeight().
However, until the TextView has been "measured", these methods return
zero.

Once the TextView has been displayed once, this measurement apparently
happens, because after the initial display, the getWidth() and
getHeight() methods then return non-zero values.

However, I would like to determine my TextView's dimensions before the
first time it gets displayed. How can I force my TextView to be
measured before the first display, so I can decide how I am going to
draw into it?

Thanks in advance.

This is my main.xml, in case it matters:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView android:id="@+id/text"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:textSize="28sp"
                  android:gravity='center_vertical|center_horizontal' />
</LinearLayout>

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to