1

我想在地图内的叠加层中勾勒出文本。我尝试了下面的代码,但结果不是很令人满意。

Paint paint = new Paint();
                paint.setTextAlign(Paint.Align.CENTER);
                paint.setTextSize(mTextSize);

                paint.setAntiAlias(true);
              //  paint.setARGB(150, 0, 0, 0); // alpha, r, g, b (Black, semi see-through)
              //  paint.setARGB(255, 255, 255, 255); 
                paint.setColor(0xFFFFFFFF );
                //paint.setStyle(Paint.Style.STROKE);
                paint.setStyle(/*Paint.Style.FILL_AND_STROKE*/Paint.Style.FILL);
                //show text to the right of the icon
                canvas.drawText(item.getTitle(), ptScreenCoord.x+(distancesShift), ptScreenCoord.y+23-mTextSize, paint);
                // again to show outline
                Paint paint2 = new Paint();
                paint2.setTextAlign(Paint.Align.CENTER);
                paint2.setTextSize(mTextSize);

                paint2.setAntiAlias(true);
                paint2.setTextAlign(Paint.Align.CENTER);
              //  paint.setARGB(150, 0, 0, 0); // alpha, r, g, b (Black, semi see-through)
              //  paint2.setARGB(255, 255, 255, 255); 
                paint2.setColor(0x00000000);
                paint2.setStyle(Paint.Style.STROKE);
                paint2.setStrokeWidth(4);

                canvas.drawText(item.getTitle(), ptScreenCoord.x+(distancesShift), ptScreenCoord.y+23-mTextSize, paint2);
4

1 回答 1

1

我知道了!!我对上面的代码做了一些小的改动,如下所示。

Paint paint = new Paint();
            paint.setTextAlign(Paint.Align.CENTER);
            paint.setTextSize(mTextSize);

            paint.setAntiAlias(true);
          //  paint.setARGB(150, 0, 0, 0); // alpha, r, g, b (Black, semi see-through)
          paint.setARGB(255, 0, 0, 0); 
            //paint.setColor(0xFFFFFFFF );
            //paint.setStyle(Paint.Style.STROKE);
            paint.setStyle(/*Paint.Style.FILL_AND_STROKE*/Paint.Style.STROKE);
            paint.setStrokeWidth(4);
            //show text to the right of the icon
            canvas.drawText(item.getTitle(), ptScreenCoord.x+(distancesShift), ptScreenCoord.y+23-mTextSize, paint);
            // again to show outline
            Paint paint2 = new Paint();
            paint2.setTextAlign(Paint.Align.CENTER);
            paint2.setTextSize(mTextSize);

            paint2.setAntiAlias(true);
            paint2.setTextAlign(Paint.Align.CENTER);
          //  paint.setARGB(150, 0, 0, 0); // alpha, r, g, b (Black, semi see-through)
           paint2.setARGB(255, 255, 255, 255); 
           // paint2.setColor(0x00000000);
            paint2.setStyle(Paint.Style.FILL);


            canvas.drawText(item.getTitle(), ptScreenCoord.x+(distancesShift), ptScreenCoord.y+23-mTextSize, paint2);
于 2012-07-19T10:56:54.497 回答