你如何绘制文字边框在Android的一个图形页面?边框、图形、文字、页面

2023-09-12 03:52:55 作者:太痴狂太忧伤

我试图得出一些文字到Android上的图形页面。文本的图纸去罚款,但它是非常难以阅读文本,因为它是白色的,没有黑边(像自然地出现在MapViews表示城市,州和国家的其他文本)。我似乎无法弄清楚如何画一个黑色边框的文本。任何人都知道如何做到这一点?

这是code我现在使用的排序(这只是例子code,在我的叠加人发现):

  @覆盖
公共无效画(油画画布,图形页面图形页面,布尔影子){
油漆textPaint =新的油漆();
textPaint.setARGB(255,255,255,255);
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setTextSize(16);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);

canvas.drawText(一些文本,100,100,textPaint);

super.draw(帆布,图形页面,阴影);
}
 

解决方案 coreldraw怎么消除边框

要做到这一点,最简单的方法是使用中风......是这样的:

  @覆盖
公共无效画(油画画布,图形页面图形页面,布尔影子){
    油漆strokePaint =新的油漆();
    strokePaint.setARGB(255,0,0,0);
    strokePaint.setTextAlign(Paint.Align.CENTER);
    strokePaint.setTextSize(16);
    strokePaint.setTypeface(Typeface.DEFAULT_BOLD);
    strokePaint.setStyle(Paint.Style.STROKE);
    strokePaint.setStrokeWidth(2);

    油漆textPaint =新的油漆();
    textPaint.setARGB(255,255,255,255);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTextSize(16);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);

    canvas.drawText(一些文本,100,100,strokePaint);
    canvas.drawText(一些文本,100,100,textPaint);

    super.draw(帆布,图形页面,阴影);
}
 

这将吸引周围的文本之外的2个像素的边框,然后画在它顶部的文本,给你一个轮廓的假象。

另外,它可能是值得设定油漆在构造函数然后就重复使用它们。

I'm trying to draw some text onto an MapView on Android. The drawing of the text goes fine, but it's very hard to read the text because it's white with no black border (like the rest of the text that appears naturally on MapViews to denote cities, states, and countries). I can't seem to figure how to draw the text with a black border. Anyone know how to do this?

This is the sort of code I'm using right now (this is just example code, found in one of my overlays):

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
	Paint textPaint = new Paint();
	textPaint.setARGB(255, 255, 255, 255);
	textPaint.setTextAlign(Paint.Align.CENTER);
	textPaint.setTextSize(16);
	textPaint.setTypeface(Typeface.DEFAULT_BOLD);

	canvas.drawText("Some Text", 100, 100, textPaint);

	super.draw(canvas, mapView, shadow);
}

解决方案

The easiest way to do this is with a Stroke... something like this:

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    Paint strokePaint = new Paint();
    strokePaint.setARGB(255, 0, 0, 0);
    strokePaint.setTextAlign(Paint.Align.CENTER);
    strokePaint.setTextSize(16);
    strokePaint.setTypeface(Typeface.DEFAULT_BOLD);
    strokePaint.setStyle(Paint.Style.STROKE);
    strokePaint.setStrokeWidth(2);

    Paint textPaint = new Paint();
    textPaint.setARGB(255, 255, 255, 255);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTextSize(16);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);

    canvas.drawText("Some Text", 100, 100, strokePaint);
    canvas.drawText("Some Text", 100, 100, textPaint);

    super.draw(canvas, mapView, shadow);
}

This will draw a border of 2 pixels around the outside of the text then draw the text over the top of it, giving you the illusion of an outline.

Also, it may be worth setting the Paints up in the constructor then just reusing them.