Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent TextView from wrapping in parent

How do I prevent a TextView, or any visual object, from wrapping to the screen and instead have them chopped off the sides? Is there some XML attribute or code to do this or is it impossible to have anything overflow from the screen?

For example, you have this:

text being wrapped

But you really want this:

text being cropped

Any ideas?

like image 699
Jay Wick Avatar asked Mar 24 '10 13:03

Jay Wick


3 Answers

check out android:maxLines="1" and if you want to add ending ... add also android:ellipsize="end"

<TextView
   android:id="@+id/name"
   android:text="i want this to crop not wrap"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:maxLines="1"
   android:ellipsize="end" />

android:singleLine="true" was deprecated in API Level 3.

like image 144
Pentium10 Avatar answered Oct 18 '22 04:10

Pentium10


You're looking for android:singleLine="true".

like image 31
lbedogni Avatar answered Oct 18 '22 03:10

lbedogni


Have you checked out android:scrollHorizontally. There is also a HorizontalScrollView if that doesn't work.

like image 5
Robby Pond Avatar answered Oct 18 '22 04:10

Robby Pond