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?
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.
In Android all layout can be nested one another.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With