I would like to center my text (tp-TextPaint) in the rectangle speech bubble figure that I have drawn on the canvas. Does any one have any idea? I have achieved it using canvas.drawText() but I want to get it using staticLayout so that the text resizes when I resize the canvas width and height. Below is my code.
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
drawPath.reset();
drawPath.moveTo(0, 0);
drawPath.lineTo(getWidth(), 0);
drawPath.lineTo(getWidth(), 100);
drawPath.lineTo((getWidth()/2) +20, 100);
drawPath.lineTo(getWidth()/2, 140);
drawPath.lineTo((getWidth()/2)-20, 100);
drawPath.lineTo(0, 100);
drawPath.lineTo(0, 0);
canvas.drawPath(drawPath, drawPaint);
TextPaint tp = new TextPaint();
tp.setColor(Color.BLACK);
tp.setTextSize(25);
tp.setAntiAlias(true);
StaticLayout sl = new StaticLayout("" + s, tp, getWidth(),Alignment.ALIGN_CENTER, 1.0f, 0.0f, true);
sl.draw(canvas);
}
tp.getWidth()andtp.getHeight()? - Mike Ortizint x = (container.getWidth() / 2) - (view.getWidth() / 2);And a similar approach would apply to the height. - Mike Ortiz