2017-02-04 90 views
8

什么是领先的保证金的涵义与什么是Android的领先优势?

的文档LeadingMarginSpansays

段落样式affec领先的利润率。在一个段落中可以有多个 前导裕量跨度​​;它们将以 的顺序进行呈现,每个订单都将其余量添加到之前的数量。领先的 保证金位于右侧至右侧段落的右侧。

但它并没有真正说出什么是领先保证金。

它像一个缩进在段落第一行的制表符?还是整个段落缩进的地方?我认为这是/lidɪŋ/而不是/lɛdɪŋ/ as in the space between lines

我想知道的原因是我想用StaticLayout制作自己的TextView。我指的是布局和StaticLayout source code的想法。我试图剪掉所有不必要的部分,但我不知道这是什么。

下面是几个SO问题,也提出了有关领先保证金的问题,但求助者似乎知道这意味着什么。

的图像将是非常有益的,但不是绝对必要的。

回答

9

前导余量指段落的缩进程度,第一行和后续行。

下面的例子应该清楚一切。以下示例中的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

主要有两种构造函数。

第一个构造函数:LeadingMarginSpan.Standard(int first, int rest)

  • first告诉像素多少缩进每个段落的首行。
  • rest告诉有多少像素缩进每个段落的其余行。

enter image description here

左侧缩进该示例通过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)

  • every告诉像素多少缩进每个段落的每一行。

enter image description here

此示例缩进每行200个像素。

LeadingMarginSpan span = new LeadingMarginSpan.Standard(200);