31

I am working on a Month View with an advanced swipe (requires current, next and previous to be loaded to allow each view to stick to your finger) which means I have many views which causes things to be a little bit slow.

            |          | #<-- screen bounderies
 ' previous ' current  '   next   ' #<-- three months loaded
    ' previous ' current  '   next   ' #<-- three months when the user drags their finger

Because of this I want to represent multiple events in a single TextView. When the user taps one of the days on the Month View (small screen), it will open the day view for that day.

On each day in the month view (typically a single day gets one seventh of the width of the screen and a little less than one seventh vertically) I would like to avoid this

|    31|
|10a:  |
| Testi|
|ng    |
|11a:  |

Instead I want

|    31|
|10a:  |
| Testi|
|11a:  |
| Anoth|

Notice that the ng is cut off instead of wrapping to the next line. This is what I am looking for.

700 Software
  • 85,281
  • 83
  • 234
  • 341

4 Answers4

48

In Java:

setHorizontallyScrolling(boolean) 

In theory, android:scrollHorizontally should do the same in XML, but there is a bug in android that stops it working.

Alice Purcell
  • 12,622
  • 6
  • 51
  • 57
Derrick
  • 481
  • 4
  • 2
  • This stops the wrapping but I also had to add setMovementMethod(new ScrollingMovementMethod()) to the TextView in order for the horizontal scrolling to work. And android:scrollbars="horizontal" in the layout file to show the scrollbar. – dmanargias Feb 25 '14 at 18:16
18

android:singleLine-----this is for xml

setTransformationMethod(TransformationMethod)-----this is for java

Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key.

I'm not sure if this will work, but it worked for me when I wanted my TextView not to wrap in my ListView

700 Software
  • 85,281
  • 83
  • 234
  • 341
auwall
  • 331
  • 3
  • 9
  • 11
    Sorry, this answer does not look sufficient. The above boxes with 5 lines are a single textview. It needs to support line returns while still prohibiting word wrap. – 700 Software Mar 30 '11 at 15:03
  • This is not answering the question at all. I don't understand why this has been upvoted so much. – stef Aug 23 '17 at 17:31
2

Currently the best answer for XML is

android:maxLines="1"

Because android:singleLine is now depreciated

stackdaddy
  • 111
  • 1
  • 10
-1

in java code

textView1.setMovementMethod(new ScrollingMovementMethod());

in XML file

android:minLines="5"

does the trick.

Alp Altunel
  • 3,324
  • 1
  • 26
  • 27