1

我在 SurfaceView 上显示文本时遇到这个问题,一些字符可以爬上其他字符,代码在这里:

private static void fakeDraw(Canvas c)
{
    Paint mPaint = new Paint();
    int color = 0xff000000;
    mPaint.setColor(color);
    mPaint.setStrokeWidth(2);
    mPaint.setStyle(Style.FILL);
    mPaint.setAntiAlias(true);

    FontMetricsInt fm = mPaint.getFontMetricsInt();
    int fh = Math.abs(fm.top); 
    int left = 0;
    int top = 100;
    Rect smallClip = new Rect(left, top-fh, left + 200, top + 30);
    Rect bigClip = new Rect(0, 0, getW(), getH());
    c.drawRect(bigClip, mPaint);
    String text1 = "Evi";
    String text2 = ">>";
    String text3 = "Tom";

    color = 0xff303030;
    mPaint.setColor(color);
    c.drawRect(smallClip, mPaint);

    color = 0xffffffff;
    mPaint.setColor(color);
    c.drawText(text1, left, top, mPaint);

    Rect bounds = new Rect();
    mPaint.getTextBounds(text1, 0, text1.length(), bounds);

    left += bounds.width();
    c.drawText(text2, left, top, mPaint);

    left -= bounds.width();
    top += 12;
    c.drawText(text3, left, top, mPaint);
    mPaint.getTextBounds(text3, 0, text3.length(), bounds);
    left += bounds.width();
    c.drawText(text2, left, top, mPaint);
    }

在第二个文本 Tom>> 的情况下全部正确显示,但第一个文本 Evi>> 不正确。问题是字符 >> 在 Evi 绘图空间中绘制(最后一个字符“i”)!可以查看您是否缩放图片,我做错了什么以及如何解决这个问题?

屏幕截图可以在这里找到:http: //img192.imageshack.us/img192/2782/imagexs.png

4

2 回答 2

0

嗯,尝试指定特定的 x / y 坐标?用数字而不是预定义的字符串?给“>>”它的绘图空间不同的坐标。

于 2010-06-07T09:40:18.177 回答
0

只需手动添加一些空间

c.drawText(text2, left + 2, top, mPaint);

或在 text2 的开头添加空格字符 (" ")

于 2010-06-07T09:47:23.263 回答