无论如何,有没有办法让 TextView 在一定数量的字符后自动换行?

发布于 2024-10-05 11:57:09 字数 179 浏览 0 评论 0原文

我可以通过编程来完成此操作,但如果我需要对多个 TextView 执行此操作,效率确实很低,而且也很耗时。

我希望 TextView 在 15 个字符后换行,每 15 个字符一次。我尝试使用 android:maxLength="15" 但这只是将字符串停止在 15 个字符处。没有新的线路或任何东西。

I can do this programmatically, but it is really inefficient, and also time consuming if I ever need to do it for multiple TextViews.

I want a TextView to go to a new line after 15 characters, every 15 characters. I tried using android:maxLength="15" but that just stopped the string at 15 characters. No new line or anything.

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

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

发布评论

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

评论(2

淡淡绿茶香 2024-10-12 11:57:09

使用 android:maxEmsandroid:singleLine="false" 结合使用指定最大字符数。

Use android:maxEms to specify a maximum amount of characters in conjunction with android:singleLine="false".

半枫 2024-10-12 11:57:09

据我所知,唯一的解决方案是以编程方式进行。由于您担心必须在多个 TextView 上执行此操作,因此我将创建一个子类 TextView 的类。在里面,你的逻辑是在每 15 个字符处换行。然后,您可以在布局中使用这个新的 TextView。

The only solution that I know of is going to be doing it programmatically. Since you worry about having to do it on multiple TextViews I would create a class that sublcasses TextView. Inside there do your logic to break to a new line on every 15th character. You can then use this new TextView in your layouts.

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