Android TextView getTextSize () includes descenders, ascenders

I can't find a mention of how getTextSize () is measured in Textview anywhere. Of the visual tests, this does not seem to include descenders, but seems to include upstream ones. It does not seem to start exactly from the baseline.

http://en.wikipedia.org/wiki/Descender

This is the closest mention of this, but Romain Guy from Google simply ignores this part of the question.

http://www.mail-archive.com/ android-developers@googlegroups.com /msg08514.html

Since I need it, since I use Compound Drawables, and I need to be able to align portable texts on different devices.

Here is the code I used to test on a connection that draws a circle that touches the edges

tvData.setTextSize(TypedValue.COMPLEX_UNIT_PX, 100); tvData.setText("agB5ãÂ"); int size = (int)tvData.getTextSize(); Drawable img = getResources().getDrawable(R.drawable.circle_white_full_72 ).mutate(); img.setBounds( 0 , 0 , size , size); tvData.setCompoundDrawables( null, null, img, null ); 

Here is the result http://i.imgur.com/zUEzB.png

since you can see that it does not use descenders and ascenders.

Here is a figurative image if others want to test http://i.imgur.com/Yhf8b.png

When resizing an image to 80% of the text size with

 int size = (int)tvData.getTextSize() *80/100; 

Here is the result, with the image transferred over 100% of the image. Maybe setCompoundrawables does its own scaling

enter image description here

I tried to measure the midpoints of the font and draw, and it is off. Here is an image highlighting it enter image description here

Finally, I moved the ejected 50 pixels to the left, and then measured the output, and it was half the height of the original line of font text to the baseline, since setTextSize was set to 100 pixels.

Android should use a different layout to scale and position the composite form. Maybe I should create one more question for this. Here is an image illuminating the baseline to the baseline. enter image description here

+6
source share
1 answer

From some trials of light, it seems, from ascent to descent (text size = descent - ascent). Has any debugging with TextPaint been checked, and I just clarified a bit:

 Paint.FontMetricsInt metrics; for(int i = 1; i < 100; i++) { mTextPaint.setTextSize(i); metrics = mTextPaint.getFontMetricsInt(); if((metrics.descent - metrics.ascent) != i) Log.v("type", "Not equal"); } 

And that remained true for every value.

+3
source

All Articles