NehaK
NehaK

Reputation: 2727

TextView new line (in multiline) issues

currently I am getting this result for a multiLine text view -

maxLines = 2

If text is -

Hello hfhfhfhfhfhfhhfhfhfhfhfhhfhfhf

Then output is :

enter image description here

But I need it like this :

enter image description here

Please help me to get this result :)

XML is

<TextView
            android:id="@+id/user_name"
            style="@style/default_text_font_face"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:scrollHorizontally="true"
            android:maxLines="2"
            android:text="Hello hffffffhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhhfhfhhfhfhfhfhhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhf"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white" />

Upvotes: 0

Views: 670

Answers (2)

Sathish Kumar J
Sathish Kumar J

Reputation: 4335

Use

 android:layout_width="match_parent"

to your TextView

EDIT1

Try the following way

<TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#535353"
    android:textColor="#ffffff"
    android:maxLines="2"
    android:text="Best Effffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffffffffff"
    android:textSize="20dp"/>

</LinearLayout>

Output

answer

I hope this may helps you

Upvotes: 1

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20910

you have use below property..

android:maxWidth="size"

Replace the size with the size you prefer. For example, 100dip.

UpDate :

xml file

<TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:maxLines="2"
        android:maxWidth="50dip"
        android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="15dp" />

Output :

enter image description here

UpDate 2 :

using match_parent.

<TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:maxLines="2"
            android:maxWidth="50dip"
            android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="15dp" />

output :

enter image description here

Upvotes: 0

Related Questions