Android Tutorial

(avery) #1
Android Tutorial 169

font. (For example, the measure of an em in a 12-point font is 12
points.)

This measurement provides better control over how much text is
viewed, regardless of the font size.Through the ems attribute, you
can set the width of the Text View.Additionally, you can use the
maxEms and minEms attributes to set the maximum width and
minimum width, respectively, of the TextView in terms of ems.

The height of a TextView can be set in terms of lines of text rather
than pixels.Again, this is useful for controlling how much text can
be viewed regardless of the font size. The lines attribute sets the
number of lines that the TextView can display.You can also use
maxLines and minLines to control the maximum height and
minimum height, respectively, that the Textview displays.

Here is an example that combines these two types of sizing
attributes. This TextView is two lines of text high and 12 ems of
text wide. The layout width and height are specified to the size of
the TextView and are required attributes in the XML schema:

<TextView
android:id=”@+id/TextView04”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:lines=”2”
android:ems=”12”
android:text=”@string/autolink_test” />


Instead of having the text only truncate at the end, as happens in
the preceding example, we can enable the ellipsize attribute to
replace the last couple characters with an ellipsis (...) so the user
knows that not all text is displayed.
Free download pdf