Tekst Centrum Android na płótnie
Próbuję wyświetlić tekst za pomocą poniższego kodu. Problem polega na tym, że tekst nie jest wyśrodkowany w poziomie. Kiedy ustawię współrzędne dladrawText
, ustawia dolną część tekstu w tej pozycji. Chciałbym, aby tekst został narysowany tak, aby tekst był również wyśrodkowany w poziomie.
To jest zdjęcie, aby wyświetlić mój problem dalej:
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
//canvas.drawRGB(2, 2, 200);
Paint textPaint = new Paint();
textPaint.setARGB(200, 254, 0, 0);
textPaint.setTextAlign(Align.CENTER);
textPaint.setTypeface(font);
textPaint.setTextSize(300);
canvas.drawText("Hello", canvas.getWidth()/2, canvas.getHeight()/2 , textPaint);
}