简体   繁体   English

在多行edittext android中将对齐方式设置为单行

[英]Set alignment to a single line in multiline edittext android

Is it possible to set alignment on a single line or some lines in multiline edittext android? 是否可以在单行或多行edittext android中的某些行上设置对齐方式? If yes, then how, if no, then why not? 如果是,那么如何,如果不是,那么为什么不呢? I get this answer from another question posted under the similar topic 我从类似主题下发布的另一个问题中得到了这个答案

"You can't apply multiple alignments within the same editText control. You'd have to solve your problem with some kind of manual padding of the text content" “您不能在同一个editText控件中应用多个对齐方式。您必须通过某种手动填充文本内容来解决您的问题”

So how can manual padding be inserted for selected lines? 那么如何为选定的行插入手动填充呢?

you can use Alignment span to set alignment for a single line and multiple lines in multiline EditText provided you know the start and end index for the line. 您可以使用Alignment span设置多行EditText中单行和多行的对齐方式,前提是您知道该行的开始和结束索引。 For example: 例如:

SpannableStringBuilder s = new SpannableStringBuilder("some text ");
AlignmentSpan span = new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE);
s.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
t.setText(s);

You can apply alignment to multiple lines at once by covering multiple line between start and end index. 您可以通过覆盖开始索引和结束索引之间的多行来一次将对齐方式应用于多行。

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

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