Android TextView问题
我有一个文本视图,在某些情况下它有很长的文本。对于长文本,它看起来太长以至于扭曲了整体布局。我想要长文本,它应该以多行形式出现。这是 TextView 的 xml
<TextView
android:id="@+id/bottomText"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:background="#000000"
android:textSize="16sp"
android:layout_gravity="center_horizontal"
android:text="@string/text_searchword"
android:layout_width="wrap_content">
</TextView>
这个问题的解决方案是什么?
I have a textview, for some cases it has long text. For long text, it appears so long that so that its distorted the total layout. I want for long text, it should appear in multi-lines. Here is xml for TextView
<TextView
android:id="@+id/bottomText"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:background="#000000"
android:textSize="16sp"
android:layout_gravity="center_horizontal"
android:text="@string/text_searchword"
android:layout_width="wrap_content">
</TextView>
What is solution of this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试添加lines属性:
此外,
wrap_content
可能不是宽度的最佳选择。检查fill_parent
。You may try to add a lines attribute:
Also
wrap_content
may not be the best choice for the width. Checkfill_parent
.像 Heiko Rupp 指出的那样设置
android:lines
属性,并设置android:maxLenght
或android:maxEms
。两者都会将您的
TextView
限制为最大 x 像素或与密度无关的像素,或者相应地限制为 x em。Set the
android:lines
property like Heiko Rupp points out and also set eitherandroid:maxLenght
orandroid:maxEms
too.Both will limit your
TextView
either to a maximum of x pixels or density independent pixels or to x ems accordingly.您可以尝试将
android:layout_width =
设置为特定大小。You can try to set the
android:layout_width =
a specific size.我认为在 xml 文件中将重力设置为“中心”可能会完成这项工作:
I think setting the gravity to "center" in the xml file might do the job: