Android Paint Style

Android在用画笔的时候有三种Style,分别是
Paint.Style.STROKE 只绘制图形轮廓(描边)
Paint.Style.FILL 只绘制图形内容
Paint.Style.FILL_AND_STROKE 既绘制轮廓也绘制内容

example

    private static final String DRAW_TEXT = "一二三四";

    private void drawText(Canvas canvas) {

        Paint paint = new Paint();
        paint.setColor(Color.RED);

        paint.setDither(true);
        paint.setStrokeWidth(3);
        paint.setTextSize(100);
        paint.setAntiAlias(true);
        //测量文本高
        Rect textBounds = new Rect();
        paint.getTextBounds(DRAW_TEXT, 0, DRAW_TEXT.length(), textBounds);
        int textH = textBounds.height();


        paint.setStyle(Paint.Style.STROKE);
        canvas.drawText(DRAW_TEXT, 0, 100 + textH * 0, paint);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawText(DRAW_TEXT, 0, 100 + textH * 1 + 50, paint);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawText(DRAW_TEXT, 0, 100 + textH * 2 + 100, paint);
    }

看一下绘制文字的效果图:
Android Paint Style_第1张图片

STROKE和FILL_AND_STROKE的粗细是一样的,FILL最细

文章很短,快餐式

你可能感兴趣的:(Android)