使用 android.graphics绘画,首先绘制一个矩形图案,然后绘制一串字符串显示在矩形图案的正中间,
// 圆角矩形 RectF rectf = new RectF(topPlaceX, topPlaceY, bottomPlaceX, bottomPlaceY); float roundPx = sizeY / 2; canvas.drawRoundRect(rectf, roundPx, roundPx, paint); //文字 Paint textpaint = new Paint(); /* 去锯齿 */ textpaint.setAntiAlias(true); textpaint.setColor(Color.parseColor("#000000")); textpaint.setTextSize(16); //x坐标居中 textpaint.setTextAlign(Paint.Align.CENTER); canvas.drawText("show", bottomPlaceX - sizeX / 2, bottomPlaceY - "sizeY/ 3, textpaint);
这是我写的,X坐标能居中,Y坐标一直不懂怎么居中