user2955394
user2955394

Reputation: 1183

How to not make a new line textview if text is not full of textview width

This is my TextView

<TextView
        android:id="@+id/tv_ContentBody"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:minLines="1"
        android:lineSpacingExtra="10dp"
        android:gravity="top"
        android:textSize="28dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:textColor="@android:color/black"
        android:text=""
        android:layout_marginTop="10dp"/>

1.When i set text "aaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb" or "aaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbbbbbb"

2.My app is running and then it's show

aaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb

or

aaaaaaaaaaaaaaaaaaaaaaa-
bbbbbbbbbbbbbbbbbbbb

I don't want it's to show like this. (i think it's auto new line when " " or "-")

3.But I want it's to show like this (not new line if text not full of TextView)

aaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbb
bbbbb

or

aaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbb
bbbbb

How to set my TextView?

EDIT

I can solve it's by replace " " with Alt+0160 and replace "-" with Alt+0150

Upvotes: 0

Views: 446

Answers (1)

Aniruddha
Aniruddha

Reputation: 4487

You can try

your_string.replace(" ", "\u00A0");

Then set the text to TextView

your_tv.setText(your_string);

Upvotes: 1

Related Questions