Questions tagged «drawtext»

10
画布上的Android Center文本
我正在尝试使用下面的代码显示文本。问题是文本没有水平居中。当我为设置坐标时drawText,它将在此位置设置文本的底部。我希望绘制文本,以便文本也水平居中。 这是进一步显示我的问题的图片: @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); //canvas.drawRGB(2, 2, 200); Paint textPaint = new Paint(); textPaint.setARGB(200, 254, 0, 0); textPaint.setTextAlign(Align.CENTER); textPaint.setTypeface(font); textPaint.setTextSize(300); canvas.drawText("Hello", canvas.getWidth()/2, canvas.getHeight()/2 , textPaint); }

2
Android Canvas.drawText
我有一个视图,我正在onDraw(Canvas canvas)方法中使用Canvas对象进行绘图。我的代码是: Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStyle(Style.FILL); canvas.drawPaint(paint); paint.setColor(android.R.color.black); paint.setTextSize(20); canvas.drawText("Some Text", 10, 25, paint); 问题是文本没有通过背景显示,我在做什么错?如果我删除canvas.drawPaint(paint)和paint.setColor(android.R.color.black),则可以在屏幕上看到文本。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.