在TextView的统一文本换行 [英] Uniform text wrapping in TextView

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

问题描述

我需要的TextView漂亮的文本换行,尤其是在头文字。

I need nice text wrapping in TextView, especially for text in headers.

有关TextView的文字换行可能是这样的,在这里的最后一个字是​​新行:

Text wrapping for TextView might look like this, where the last word is in new line:

| ========================= |
|          =====            |

这是什么,我想有被包裹其中,线的宽度更平和:

That what I would like to have is wrapping where lines width is more equable:

|     ================      |
|      ==============       |

这很容易添加的'\\ n'的一种语言测试它在不同的屏幕尺寸,但不是当有超过10个的翻译。

It's easy to add '\n' for one language and test it on different screen sizes but not when there is more than 10 translations.

推荐答案

我已经修改的TextView创造UniformTextView。 TextView的的来源调查后,我决定尽量减少TextView的宽度有preferred行数。

I have modified TextView and created UniformTextView. After investigating of TextView sources I have decided to minimize TextView's width to have preferred lines number.

    <pl.dziobas.uniformtextview.UniformTextView
        android:text="@string/sample_text"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        app:prefLineNumber="2"
        style="@style/sample_style" />

它的工作满意我。结果

It works satisfactorily for me.

源代码可以在 github上

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

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