在 Android 多行 TextView 中禁用自动换行

发布于 2024-10-19 12:01:43 字数 642 浏览 9 评论 0原文

我正在开发带有高级滑动功能的月视图(需要加载当前、下一个和上一个视图,以允许每个视图粘在您的手指上),这意味着我有很多视图,这导致事情有点慢。

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

因此,我想在单个 TextView 中表示多个事件。当用户点击月视图(小屏幕)上的某一天时,它将打开当天的日视图。

在月视图中的每一天(通常一天的宽度为屏幕宽度的七分之一,垂直方向略小于七分之一),我想避免这种情况

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

相反,我想

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

注意 ng被切断而不是换行到下一行。这就是我正在寻找的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绿光 2024-10-26 12:01:44

在 Java 中:

setHorizontallyScrolling(boolean) 

理论上, android:scrollHorizo​​ntally 应该在 XML 中执行相同的操作,但是 android 中存在一个错误,导致它无法工作。

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.

心欲静而疯不止 2024-10-26 12:01:44

android:singleLine-----这是用于 xml

setTransformationMethod(TransformationMethod)-----这是用于 java

将文本限制为单个水平滚动行,而不是让它换行到多行,并在按 Enter 键时前进焦点而不是插入换行符。

我不确定这是否有效,但当我希望 TextView 不包含在 ListView 中时,它对我有用

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

握住我的手 2024-10-26 12:01:44

目前 XML 的最佳答案是

android:maxLines="1"

因为 android:singleLine 现已贬值

Currently the best answer for XML is

android:maxLines="1"

Because android:singleLine is now depreciated

深海少女心 2024-10-26 12:01:44

java 代码中

textView1.setMovementMethod(new ScrollingMovementMethod());

在 XML 文件中的

android:minLines="5"

就可以解决这个问题。

in java code

textView1.setMovementMethod(new ScrollingMovementMethod());

in XML file

android:minLines="5"

does the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文