问题描述
我想设置保证金的TextView(每个段落的不是第一行)我已经使用code,只有第一行:
i want to set margin for only first line of TextView (Not first line of each paragraph)?I have used code:
SpannableString s = new SpannableString("this is a test"+"\n"+"this is a test");
s.setSpan(new android.text.style.LeadingMarginSpan.Standard(30, 0), 0, s.length(), 0);
textView .setText(s);
下面保证金将被用于所有Paragraph..I不愿that.I想要的保证金仅适用于第一线only..Pls帮助第一行设置。
Here margin will be set for first line of all Paragraph..I don't want that.I want the margin to be only applied to 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的文本在以后,你可以使用子()
方法来获取字符串中的一部分,即 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的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!