限制TextView中的行数 [英] Limit numbers of lines in TextView

查看:73
本文介绍了限制TextView中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可滚动的textView,我想限制显示的行数,但是xml属性不起作用:

I have a scrollable textView, and I want to limit the number of lines displayed, however xml properties are not working :

<TextView
   android:id="@+id/tv_addesc"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:scrollbars="vertical"
   android:maxLines="12"
   android:textColor="#FFFFFFFF"
   android:textSize="15sp" />

显示的行数是50,并且文本中有900个字符.

the number of lines displayed is 50 and there are 900 chars in the text.

如何限制显示的行数并使之可滚动?

How can I limit the number of lines displayed and make it scrollable ?

我测试了846行和15824个字符,无论设置了什么不同的属性,都会显示整个文本.

Edit : I tested with 846 lines and 15824 chars, the whole text is displayed regardless of different properties set.

Edit:除textView之外,还有第二个组件,当我删除它时,它起作用了,所以我将找到一种解决方法.谢谢!

Edit : there was a second component besides the textView, when i removed it it worked, so I will find a workaround. Thank you !

推荐答案

您只需要在 TextView 中设置如下几行:

You just have to set a number of lines in your TextView like this:

android:maxLines = "10"

,并且您还必须添加:

android:minLines="1"

如果您不使用滚动条,则无需执行其余操作

和一个表示此TextView应该可以垂直滚动的属性:

and a property which says that this TextView should be scrollable vertically:

android:scrollbars = "vertical"

并使用您的Java代码:

And in your Java-code:

yourTextView.setMovementMethod(new ScrollingMovementMethod())

这篇关于限制TextView中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆