span 的cdir_段落级Span解析

1 简介

之前已经讲过TextView的基础知识,现在在这进一步进行讲解,这篇文字主要讲解如何给TextView设置段落级别的Span。如果一个Span想要影响段落层次的文本格式,则需要实现ParagraphStyle。

2 ParagraphStyle

ParagraphStyle是一个接口,通过查看Android源码,我们发现这个接口里面什么方法也没有定义,因此,我们可以认为,这个接口无非是标识实现这个接口的Span为段落级别的Span。

在Android源码中又继续定义了几个接口实现了ParagraphStyle接口。

ParagraphStyle

LeadingMarginSpan:用来处理像word中项目符号一样的接口;

AlignmentSpan:用来处理整个段落对其的接口;

LineBackgroundSpan:用来处理一行的背景的接口;

LineHeightSpan:用来处理一行高度的接口;

TabStopSpan:用来将字符串中的"\t"替换成相应的空行;

3 LeadingMarginSpan

LeadingMarginSpan用来控制整个段落左边或者右边显示某些特定效果,里面有两个接口方法。

/**

* Returns the amount by which to adjust the leading margin. Positive values

* move away from the leading edge of the paragraph, negative values move

* towards it.

*

* @param first true if the request is for the first line of a paragraph,

* false for subsequent lines

* @return the offset for the margin.

*/

public int getLeadingMargin(boolean first);

/**

* Renders the leading margin. This is called before the margin has been

* adjusted by the value returned by {@link #getLeadingMargin(boolean)}.

*

* @param c the canvas

* @param p the paint. The this should be left unchanged on exit.

* @param x the current position of the margin

* @param dir the base direction of the paragraph; if negative, the margin

* is to the right of the text, otherwise it is to the left.

* @param top the top of the line

* @param baseline the baseline of the line

* @param bottom the bottom of the line

* @param text the text

* @param start the start of the line

* @param end the end of the line

* @param first true if this is the first line of its paragraph

* @param layout the layout containing this line

*/

public void drawLeadingMargin(Canvas c, Paint p,

int x, int dir,

int top, int baseline, int bottom,

CharSequence text, int start, int end,

boolean first, Layout layout);

LeadingMarginSpan2还多规定了一个方法。

/**

* Returns the number of lines of the

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值