There is a view in which I want to write text on the canvas.

First, I set the text size in paint be equal to the height of the view, and then maybe I make a mistake, I do not understand:

 this.fontSize = getHeight(); this.paint.setTextSize(fontSize); Rect textBounds = new Rect(); this.paint.getTextBounds(myText, 0, myText.length(), textBounds); 

Then I draw the text:

 canvas.drawText( myText, canvas.getWidth() - textBounds.width(), canvas.getClipBounds().top + textBounds.height(), paint); 

But the text is higher in height than the view itself. I bring in logs:

 fontSize = 32 textBounds.height() = 22 

The question is how to set the size of the text so that it would be the same size in height as the view itself?

  • ? Layout.LayoutParams params = (? Layout.LayoutParams) view.getLayoutParams (); int height = params.height; - Flippy
  • Sorry, but the comment is useless. - Kirill Stoianov
  • Getting the height of something not right - Flippy
  • I know how to get the height of the view, the question is how to set the size of the text in paint so that it matches the height of the view. textBounds.height () returns the height value less than what I set in paint! - Kirill Stoianov
  • Maybe it's in the metric (px, etc.) - sapeg

0