前导余量指段落的缩进程度,第一行和后续行。
下面的例子应该清楚一切。以下示例中的TextView包含两段文本(即,它们包括\n
字符)。
这里是已使用的样板代码:
LeadingMarginSpan span = ... // substitute this line with the examples below
TextView textView = (TextView) findViewById(R.id.textView) ;
SpannableString spannableString = new SpannableString("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
spannableString.setSpan(span, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannableString);
主要有两种构造函数。
第一个构造函数:LeadingMarginSpan.Standard(int first, int rest)
first
告诉像素多少缩进每个段落的首行。
rest
告诉有多少像素缩进每个段落的其余行。
左侧缩进该示例通过20个像素的第一行和所述行由100个像素的其余部分。 (没有填充已被添加到TextView
。)
LeadingMarginSpan span = new LeadingMarginSpan.Standard(20, 100); // left example
在右边的例子示出了由100缩进第一线和所述线不缩进在所有的其余部分。
LeadingMarginSpan span = new LeadingMarginSpan.Standard(100, 0); // right exmaple
第二个构造:LeadingMarginSpan.Standard(int every)
此示例缩进每行200个像素。
LeadingMarginSpan span = new LeadingMarginSpan.Standard(200);