user733284
user733284

Reputation: 935

Drawing mirror text on canvas

I'm trying to draw on a canvas a text and below another text that is the mirror of this text (that looks like shadow)

I'm using it in the "onDraw" method

Is there a simple way to do it?

Thanks in advance, Lior

Upvotes: 2

Views: 3406

Answers (1)

eyespyus
eyespyus

Reputation: 1576

sure can. You will need to scale the canvas first. Try this out:

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();

Try different values for the scale Y value to get effect you want.

enter image description here

Upvotes: 7

Related Questions