Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fit TextView text on one line with WRAP_CONTENT LayoutParams

Say I have a TextView with some dynamic text. This TextView is being placed inside a LinearLayout with WRAP_CONTENT LayoutParams for both width & height.

Problem is that some of the text is - breaking onto second(or third) line - wrapping. I want to avoid this.

I have tried to replace all ' '(space chars) with non-breaking space character. This hasn't helped. The text still breaks. I also cannot set the TextView's maxLines=1 because there are some newline chars in the String-data.

I am not sure if any code samples need to be included. If there;s something specific, please do ask me in a comment.

Any help will be greatly appreciated :~)

like image 811
Athena Avatar asked Dec 14 '22 16:12

Athena


1 Answers

@Joe B. Answer is right. but android:singleLine="true" is deprecated. You need to use

android:maxLines="1"
like image 116
Md Shihab Uddin Avatar answered May 12 '23 06:05

Md Shihab Uddin