How to configure TextView to display text on one line in Android

I set TextView as the display. I want to display the operation in progress on one line, for example:

9856243187 + 2457896123 - 214583 

The problem is that when the input reaches the edge of the TextView, it goes to the next line.

So, is there a way to avoid this behavior and keep the input on one line, even if it goes off the screen?

+15
source share
9 answers

You should use android:maxLines="1" in the TextView tag. android:singleLine="true" deprecated .

+46
source
 android:singleLine="true" 

- answer

Update:

Attribute

android:singleLine deprecated from API level 3, you can use

 android:maxLines="1" 
+11
source

Tl dr

For new users who see this question, use android:singleLine="true" . Ignore failure warnings.

Description

According to this error report , setting android:maxLines="1" may cause your application to crash when certain values ​​are set in android:ellipsize . Apparently, this affects most Android devices running 4.1 Jellybean through 6.0.1 Marshmallow (fixed in 7.0 Nougat). Depending on your device, your mileage may vary. However, if you as a developer are focused on a wide range of devices, it is better to use android:singleLine="true" to prevent crashes.

+7
source

add code to text box

 android:singleLine="true" 
+3
source

Set TextView to one line.

Take a look at this

+2
source

If you want to manually scroll through the single-line content, you must use the TextView inside the HorizontalScrollView

 <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="16dp" android:paddingTop="16dp" android:scrollHorizontally="true" android:singleLine="true" android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget" /> </HorizontalScrollView> 
+1
source

This code worked for me:

 android:singleLine="true" 
+1
source

Thanks guys, one line did the tricks, but I also had to remove the ellipsis:

 android:ellipsize="none" 
0
source

Can you try this?

 <TextView android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit ="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" android:scrollHorizontally="true" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 

Hope this helps you.

0
source

All Articles