边距设置为 textView 的第一行 [英] margin set to first line of textView

查看:33
本文介绍了边距设置为 textView 的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想为 TextView 的第一行设置起始边距(不是每个段落的第一行)?我使用了以下代码:

I want to set start margin only for the first line of TextView (Not first line of each paragraph)? I have used the following code:

SpannableString s = new SpannableString("this is a test"+"
"+"this is a test");
s.setSpan(new android.text.style.LeadingMarginSpan.Standard(30, 0), 0, s.length(), 0);
textView .setText(s);

此处为段落的所有行设置了起始边距.我不希望这样.我希望仅将起始边距应用于第一行..请帮助..

Here start margin is getting set for all lines of the Paragraph.. I don't want that. I want start margin to be applied for first line only.. Pls help..

推荐答案

正如这里所建议的,我也认为最好的解决方案是在开头添加几个空格.如果您只需要 TextView 的第一行的边距空间,我看不出您需要做一些非常高级的事情的任何理由.

As it has been suggested here, I also think the best solution is to simply add a few spaces at the beginning. If you only need the margin space at the very first line of the TextView, I don't see any reason why you'd need to do something really advanced.

如果以后需要更改或使用TextView中的文本,可以只使用substring()方法只获取字符串的一部分,即s.substring(2, s.length());

If you need to change or use the text in the TextView at a later point, you can just use the substring() method to get only a part of the string, i.e. s.substring(2, s.length());

这不是一个完美的解决方案,但我认为它会做到.

It's not a perfect solution, but I think it'll do.

这篇关于边距设置为 textView 的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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