0

在地图上使用 Canvas 和 Paint 标记几个标记并添加名称。但我能够看到文本只有 9 个字符被隐藏(不可见)。怎么做?

private Bitmap drawTitleOnMarkerIcon(MarkingInfo markingInfo) {
    Bitmap bm = BitmapFactory.decodeResource(getResources(), AddLocationTypeIcon.getIcon(markingInfo.getType())).copy(
            Bitmap.Config.ARGB_8888, true);

    Canvas canvas = new Canvas(bm);
    Paint paint = new Paint();
    paint.setColor(Color.BLUE);
    paint.setAntiAlias(true);
    paint.setFakeBoldText(true);
    paint.setTextSize(16);
    paint.setTextAlign(Align.LEFT);
    canvas.drawText(markingInfo.getName(), 0, 60, paint);

    BitmapDrawable draw = new BitmapDrawable(getResources(), bm);
    return draw.getBitmap();
}

我应该能够看到完整的文本,当我有超过 15 个字符时,我只需要将它换行到下一行。之前搜索了许多网站并发布了查询,但我没有解决方案。请帮助完成这项任务

4

1 回答 1

0
private Bitmap textAsBitmap(String text, float textSize, int textColor) {
    Paint paint = new Paint();
    paint.setTextSize(textSize);
paint.setColor(textColor);
    paint.setFakeBoldText(true);
    paint.setTextAlign(Paint.Align.LEFT);
    int width = (int) (paint.measureText(text) + 0.5f); // round
    float baseline = (int) (-paint.ascent() + 0.5f); // ascent()is negative
    int height = (int) (baseline + paint.descent() + 0.5f);
Bitmap image = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
canvas.drawText(text, 0, baseline, paint);
    return image;
    }




MarkerOptions().title(Name()).icon(BitmapDescriptorFactory.fromBitmap(textAsBitmap)); 
于 2014-06-23T09:00:42.207 回答