1

I have a custom View which is supposed to draw some text bottom aligned. Size of text should be 50% of view height.

How should I change this code to work correctly?

@Override
protected void onDraw(Canvas canvas)
{
    float h = getMeasuredHeight();
    float textHeight = h*0.5f;
    paint.setTextSize(textHeight);
    String str = "Abcdefghijklm";

    paint.getTextBounds(str, 0, str.length(), bounds);
    float height = bounds.height();
    float yPos = height;
    canvas.drawText(str, 0, yPos, paint);
}
activity
  • 2,653
  • 3
  • 20
  • 44

1 Answers1

0

Replace your yPos to:

float yPos = getHeight() - bounds.getHeight();
Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/16568536) – basvk Jun 30 '17 at 13:21
  • This is the answer bro, notice that i provided a working code to replace in her own code – Marcos Vasconcelos Jun 30 '17 at 13:56