答案 0 :(得分:1)
您可以使用以下方式将某些文字/视图覆盖在另一个视图上:
在第三种方法中,您完全负责绘图。例如,要在自定义视图的内容上绘制位图,可以像这样覆盖onDraw():
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(mBitmap, 0, 0, mPaint);
}
答案 1 :(得分:1)
这有很多步骤涉及文本,位图,画布,矩形。例如:
int textSize = textSizeBar.getProgress();
String textToDraw = textIn.getText().toString();
Bitmap newBitmap = bitmapOriginal.copy(bitmapOriginal.getConfig(), true);
Canvas newCanvas = new Canvas(newBitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
paint.setTextSize(textSize);
Rect bounds = new Rect();
paint.getTextBounds(textToDraw, 0, textToDraw.length(), bounds);
int x = 0;
int y = newBitmap.getHeight();
newCanvas.drawText(textToDraw, x, y, paint);
image1.setImageBitmap(newBitmap);
image2.setImageBitmap(newBitmap);
此示例来自这个非常好的网站:http://android-er.blogspot.com
完整代码可在此处找到:http://android-er.blogspot.com/2015/03/draw-text-on-bitmap.html
谢谢。