Android绘制面板设置绘制文本

我做了一个绘图板。我想在面板背景中添加文字,但是失败了。我不知道为什么

这是我的代码:

 public PaintView(Context context,AttributeSet attrs) {
    super(context,attrs);
    mPaint = new Paint();
    mPaint.setColor(DEFAULT_COLOR);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setXfermode(null);
    mPaint.setalpha(0xff);
    mEmboss = new EmbossMaskFilter(new float[] {1,1,1},0.4f,6,3.5f);
    mBlur = new BlurMaskFilter(5,BlurMaskFilter.Blur.NORMAL);
}

 public void init(DisplayMetrics metrics) {
    int height = metrics.heightPixels;
    int width = metrics.widthPixels;
    mBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);
    currentColor = DEFAULT_COLOR;
    strokeWidth = BRUSH_SIZE;
    Paint p = new Paint();
    p.setTextSize(50);
    p.setTextAlign(Paint.Align.CENTER);
    p.setColor(Color.BLACK);
    mCanvas.drawText("HI",getLeft()+10,getTop()+30,p);
}
 protected void onDraw(Canvas canvas) {
    canvas.save();
    mCanvas.drawColor(backgroundColor);

    for (FingerPath fp : paths) {
        mPaint.setColor(fp.color);
        mPaint.setStrokeWidth(fp.strokeWidth);
        mPaint.setMaskFilter(null);

        if (fp.emboss)
            mPaint.setMaskFilter(mEmboss);
        else if (fp.blur)
            mPaint.setMaskFilter(mBlur);

        mCanvas.drawPath(fp.path,mPaint);


    }

    canvas.drawBitmap(mBitmap,mBitmapPaint);
    canvas.restore();
}

我设置了“ HI” drawText,但没有显示。

谢谢。

这是我的代码 https://github.com/cool3690/bsic 我希望我可以这样做 enter image description here

xzx1xzx 回答:Android绘制面板设置绘制文本

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3098369.html

大家都在问