I would like to have a text displayed on an Android widget (remote views) not wrap over its text to the next line, if the text is longer than the Textview
's width. Instead of that, I would like to have the Textview cut any extra text. I have tried many things without success.
Here is the XML code for the TextView
:
<TextView
android:id="@+id/txtInformation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:maxWidth="220dp"
android:lines="1"
android:text="Long text long text long text long text"
android:textSize="13sp" />
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
you can extend the TextView class and overwrite the setText() function. In this function you check for text length or word cound. Better than counting the text length or the word cound a better way would be to use the "maxLines" attribute along with "ellipsize" attribute to attain the desired effect.
In your layout XML, use android:maxLines="1"
or android:singleLine="true"
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