嗨,我有空间标记生成器自动完成多种文本浏览和使用ReplacementSpan在每个联系人的背景颜色变化
我的自定义更换代码
public class MyForgroudSpan : ReplacementSpan
{
public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
{
var rect = new RectF(x , top, x + paint.MeasureText(text, start, end)+8, bottom);
paint.Color = Android.Graphics.Color.ParseColor("#E5E5E6");
canvas.DrawRect(rect, paint);
paint.Color = Android.Graphics.Color.Black;
int xPos = Java.Lang.Math.Round(x + (8 / 2));
int yPos = (int)((canvas.Height / 2) - ((paint.Descent() + paint.Ascent()) / 2));
canvas.DrawText(text, start, end, xPos, yPos, paint);
}
public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
{
return Java.Lang.Math.Round(paint.MeasureText(text, start, end))+8;
}
}
我在这里设置spannable串
SpannableStringBuilder ssb = new SpannableStringBuilder(Text.trim());
ssb.SetSpan(new MyForgroudSpan(), x, x + c.Length, SpanTypes.ExclusiveExclusive);
其确定当多个自动完成的TextView有单线,但它来多线意味着它重叠文本
请参阅屏幕
1.单行
2.multiline图像
当我用这样的y值
canvas.DrawText(text, start, end, xPos, y, paint);