lbenedetto
lbenedetto

Reputation: 2114

Prevent android from splitting line at a specific point?

I have the text Improve and Personalize App Name.

The way I have it in my layout, it runs out of space and wraps to the next line such that the text is like Improve and Personalize App\nName.

But it looks weird to have the app name be split across lines.

How do I specify to Android not to split the app name?

Upvotes: 0

Views: 193

Answers (2)

user8959091
user8959091

Reputation:

The result depends on the screen size of the device. So what you see is weird for the device you test on. It can be more weird in other devices or perfect for others. If you really need this text in one line then you must create different layouts of the activity/fragment for different screen sizes (even for different orientations) and in each of them define smaller or bigger textsize for the text.

Or use 2 TextViews in a horizontal LinearLayout:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Improve and Personalize "/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name"/>

</LinearLayout>

If the 2nd TextView is too big it will fall down to the next line.

Upvotes: 1

lbenedetto
lbenedetto

Reputation: 2114

Not sure if this is the best way, but it works.

You can use a character that looks like a space but isn't a space. Android will consider your app name to be one word, even if it isn't.

I used &#160; so my string became Improve and Personalize App&#160;Name

Upvotes: 2

Related Questions