如何在 Android TextView 中将文本换行到下一行?

发布于 2024-10-01 22:41:27 字数 425 浏览 1 评论 0原文

我正在使用以下 TextView 在其中显示一些数据:

<TextView android:id="@+id/notificationText" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:textSize="18sp"
        android:inputType="textMultiLine"
        android:maxLines="2"
        android:layout_paddingRight="20dip"
        android:textColor="#ffffff"/>

我想将文本换行到下一行。我该怎么做?

I am using following TextView to display some data in it:

<TextView android:id="@+id/notificationText" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:textSize="18sp"
        android:inputType="textMultiLine"
        android:maxLines="2"
        android:layout_paddingRight="20dip"
        android:textColor="#ffffff"/>

I want to wrap text to next line. How can I do this?

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

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

发布评论

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

评论(4

静水深流 2024-10-08 22:41:27

您必须在 xml 中设置 android:scrollHorizo​​ntally="false"

you must set android:scrollHorizontally="false" in your xml.

秋意浓 2024-10-08 22:41:27

在某些情况下,它可以通过在文本视图上将宽度设置为 0dp 来工作。

android:layout_width="0dp"

这是原始答案的链接。

In Some case It works by setting width to 0dp on text views.

android:layout_width="0dp"

here is a link to original answer.

季末如歌 2024-10-08 22:41:27

您也可以尝试

android:inputType="textMultiLine"

在 XML 中。这对我有用。

You could also try

android:inputType="textMultiLine"

in your XML. This worked for me.

土豪 2024-10-08 22:41:27

你需要设置

 android:minLines="2"

You need to set

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