80,490
社区成员
发帖
与我相关
我的任务
分享

public class BackgroundColorWithoutLineHeightSpan implements LineBackgroundSpan {
private int mBackgroundColor;
private int lineSpaceing;
private Rect mBgRect;
public BackgroundColorWithoutLineHeightSpan(int backgroundColor, int lineSpace) {
super();
mBackgroundColor = backgroundColor;
lineSpaceing = lineSpace;
// Precreate rect for performance
mBgRect = new Rect();
}
@Override
public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) {
final int textWidth = Math.round(p.measureText(text, start, end));
final int paintColor = p.getColor();
// Draw the background
mBgRect.set(left,
top,
left + textWidth,
bottom - lineSpaceing);
p.setColor(mBackgroundColor);
c.drawRect(mBgRect, p);
p.setColor(paintColor);
}
}
如果对中间的行不能铺满不满意的话,那就把right设置为屏幕的宽度,具体自己把握。