Android TextView问题

发布于 2024-11-01 01:24:00 字数 532 浏览 8 评论 0原文

我有一个文本视图,在某些情况下它有很长的文本。对于长文本,它看起来太长以至于扭曲了整体布局。我想要长文本,它应该以多行形式出现。这是 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 技术交流群。

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

发布评论

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

评论(4

挽梦忆笙歌 2024-11-08 01:24:00

您可以尝试添加lines属性:

android:lines="4"

此外,wrap_content可能不是宽度的最佳选择。检查fill_parent

You may try to add a lines attribute:

android:lines="4"

Also wrap_content may not be the best choice for the width. Check fill_parent.

沉默的熊 2024-11-08 01:24:00

像 Heiko Rupp 指出的那样设置 android:lines 属性,并设置 android:maxLenghtandroid:maxEms

两者都会将您的 TextView 限制为最大 x 像素或与密度无关的像素,或者相应地限制为 x em。

Set the android:lines property like Heiko Rupp points out and also set either android:maxLenght or android:maxEms too.

Both will limit your TextView either to a maximum of x pixels or density independent pixels or to x ems accordingly.

倾城月光淡如水﹏ 2024-11-08 01:24:00

您可以尝试将 android:layout_width = 设置为特定大小。

You can try to set the android:layout_width = a specific size.

你又不是我 2024-11-08 01:24:00

我认为在 xml 文件中将重力设置为“中心”可能会完成这项工作:

    android:gravity="center"

I think setting the gravity to "center" in the xml file might do the job:

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