在画布上绘制镜像文本

时间:2011-11-23 19:14:35

标签: android

我正在尝试在画布上绘制文本,并在另一个文本下方绘制,该文本是此文本的镜像(看起来像阴影)

我在“onDraw”方法中使用它

有一种简单的方法吗?

提前致谢, 利奥尔

1 个答案:

答案 0 :(得分:6)

肯定可以。您需要先缩放画布。试试这个:

paint.setTextSize(44);
int cx = this.getMeasuredWidth() / 2;
int cy = this.getMeasuredHeight() / 2;
paint.setColor(Color.RED);
canvas.drawText("Hello", cx, cy, paint);

canvas.save();
canvas.scale(1f, -0.5f, cx, cy);
paint.setColor(Color.GRAY);
canvas.drawText("Hello", cx, cy, paint);
super.onDraw(canvas);
canvas.restore();

为比例Y值尝试不同的值以获得您想要的效果。

enter image description here