Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent word-break in a TextView

I have a TextView with fixed width as follows:

<TextView     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:gravity="center"     android:textSize="12sp"     tools:text="Health Department"     android:layout_marginTop="4dp"     android:maxLines="2"     /> 

... But it appears like:

   |Health Dep-|    |  artment  | 

... While I want it to be:

   |  Health  |    |Department| 

What XML attribute can I use to do this?

like image 309
Asym Avatar asked Nov 28 '16 20:11

Asym


People also ask

What is EMS in TextView?

ems is a unit of measurement. The name em was originally a reference to the width of the capital M. It sets the width of a TextView/EditText to fit a text of n 'M' letters regardless of the actual text extension and text size. Eg : android:ems Makes the EditText be exactly this many ems wide.

Can we Nest TextView inside TextView?

In Android all layout can be nested one another.


1 Answers

From api 23 you can choose the break strategy and that should fix your issue.

By default android for TextView use BREAK_STRATEGY_HIGH_QUALITY and that is causing the words breaking using hyphens.

If you want to avoid that, you can set the break strategy to BREAK_STRATEGY_SIMPLE.

You can find more information in the api doc.

I hope that helps you.

like image 150
Manolo Garcia Avatar answered Sep 22 '22 14:09

Manolo Garcia