dev_android
dev_android

Reputation: 8818

Android TextView Problem

I have a textview, for some cases it has long text. For long text, it appears so long that so that its distorted the total layout. I want for long text, it should appear in multi-lines. Here is xml for TextView

<TextView
            android:id="@+id/bottomText"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:background="#000000"
            android:textSize="16sp"
            android:layout_gravity="center_horizontal"
            android:text="@string/text_searchword"
            android:layout_width="wrap_content">
</TextView>

What is solution of this problem?

Upvotes: 2

Views: 3740

Answers (4)

Sahil Sharma
Sahil Sharma

Reputation: 41

I think setting the gravity to "center" in the xml file might do the job:

    android:gravity="center"

Upvotes: 0

Octavian Helm
Octavian Helm

Reputation: 39604

Set the android:lines property like Heiko Rupp points out and also set either android:maxLenght or android:maxEms too.

Both will limit your TextView either to a maximum of x pixels or density independent pixels or to x ems accordingly.

Upvotes: 0

Bastaix
Bastaix

Reputation: 845

You can try to set the android:layout_width = a specific size.

Upvotes: 0

Heiko Rupp
Heiko Rupp

Reputation: 30934

You may try to add a lines attribute:

android:lines="4"

Also wrap_content may not be the best choice for the width. Check fill_parent.

Upvotes: 1

Related Questions