I can't find anywhere there is a mention of how the getTextSize() in Textview is measured. From visual tests it doesn't seem to be including descenders, but seems to include ascenders. It doesn't appear to start exactly from the baseline also.
http://en.wikipedia.org/wiki/Descender
This is the closest mention of it but Romain Guy from Google just ignores that part of the question.
http://www.mail-archive.com/[email protected]/msg08514.html
As I need this as I am using Compound Drawables and I need to be able to align the drawable to the text on different devices.
Here is code I used to test on a compound drawable a circle that touches 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
as you can see it doesn't seem to use the descenders and ascenders.
Here is the drawable image, if others want to test http://i.imgur.com/Yhf8b.png
When changing the image to 80% of the text size using
int size = (int)tvData.getTextSize() *80/100;
Here is the result, with the image transposed on top of the 100% image. Maybe setCompoundrawables is doing it's own scaling
I tried measuring midpoints of the font and drawable and it is off. Here is an image highlighting it
Finally I moved the drawable 50pixels to the left, and then measured the output and it was half the height of the font text baseline to baseline, as the setTextSize was set at 100px.
Android must be using some other layout to scale and position the compound drawable. Maybe I should create another question for this.
Here is an image highlighting baseline to baseline.
TextView is the user interface which displays the text message on the screen to the user. It is based on the layout size, style, and color, etc. TextView is used to set and display the text according to our specifications.
On your Android phone or tablet, open a document in the Google Docs app. Double-tap the place in your document you want to edit. tap Paragraph. Next to "Line spacing," use the arrows to choose the amount of space you want between the lines in the paragraph.
You can use android:includeFontPadding="false" to get rid of the default padding in a TextView . Android docs say this about the attribute: Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly.
Inside the onClick(View v) implementation add: v. getId(); To determine whice TextView pressed.
From some light testing, it appears to be from ascent to descent (text size = descent - ascent). Did some debugging with a TextPaint to verify, and just to be a little more specific, I did:
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 it remained true for each value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With