简体   繁体   English

在TextView中设置文本自定义

[英]Set Text Customization in TextView

I have a text that is sometimes too high and at times one word. 我的文字有时过高,有时一个字。

在此处输入图片说明

How to put the text in this TextView so that the first two lines are located around the specified spacing? 如何将文本放在此TextView中,以使前两行位于指定的间距附近?

Should this be done by 2 TextView? 应该由2 TextView完成吗?

If yes, how can I figure out how much text is placed on the top two lines? 如果是,我如何确定在前两行中放置了多少文本?

You can use a Spannable to add customizations to a string inside a TextView. 您可以使用Spannable将自定义添加到TextView中的字符串。

The styling android blog has an excellent post about it: https://blog.stylingandroid.com/introduction-to-spans/ 样式化的android博客上有一篇很棒的文章: https : //blog.stylingandroid.com/introduction-to-spans/

But looking to your print, it seems that the first row will always have a style and the rest another. 但是从您的印刷品来看,似乎第一行将始终具有样式,其余行将具有另一种样式。 With this, using two TextViews and customizing the view directly is a better option for code and performance. 这样,使用两个TextView并直接自定义视图是代码和性能的更好选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM