Disable Word Wrap in an Android Multi-Line TextView

三世轮回 提交于 2019-11-30 06:21:01
Derrick

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.

auwall

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

Currently the best answer for XML is

android:maxLines="1"

Because android:singleLine is now depreciated

in java code

textView1.setMovementMethod(new ScrollingMovementMethod());

in XML file

android:minLines="5"

does the trick.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!