In the previous image, you can specify textSize in Paint to get the relevant information.
Get the corresponding information from the code:
-
mPaint.setTextSize(80); *// Set the font to italic * mPaint.setTypeface(Typeface.create("", Typeface.ITALIC)); *// FontMetrics object * FontMetricsInt fontMetrics = mPaint.getFontMetricsInt(); fontMetrics.leading; fontMetrics.ascent; fontMetrics.baseLine; fontMetrics.descent; fontMetrics.top; fontMetrics.bottom; Copy the code
MPaint. GetFontMetric () is used to get a float, and there is an error between the calculated value and the actual drawn value measured by the system.
Under the said IncludedFontPadding:
IncludedFontPadding = false; It removes the gap between the top and the bottom.
Calculation formula:
IncludedFontPadding=false: height1=Descent – Ascent; (Ascent is negative)
IncludedFontPadding =true: height2=bottom – top;
Results: height2 > height1; I just have extra space.
The relationship between some parameters in TextView and some parameters in mobile phone system
scaledTextSize : Sp
textSize : PX
The text size is set to change the Activity Resource configuration information fontScale, not scaleDensity. Please pay attention!
Display text size set by the system | standard | big | Very large | jumbo |
---|---|---|---|---|
fontScale= | 1 | 1.15 | 1.3 | 1.45 |
For example:
android : textsize =”10sp”
When the phone is set to extra large,
ScaledTextSize = 10*1.45 = 14.5sp;
textSize = scaledTextSize*scaleDensity = 29px; (If scaleDensity =2)
Fixed text size:
From the above, we want to set the textView not to change with the system display text size. We can set the size to dp value.
Android: TextSize =” 10DP “,dp will not do fontScale conversion, so even if the phone system text display, textsize is 20px.
Dynamically changing the fontScale of a Resource
By setting fontScale, you can change the text size of the interface, no matter how big you want (recently developed for aging, for the elderly home, of course, the font to be super infinite).
Resources resources = activity.getResources(); if(resources ! = null && resources.getConfiguration().fontScale ! = fontScale) { Configuration configuration = resources.getConfiguration(); configuration.fontScale = fontScale; resources.updateConfiguration(configuration, resources.getDisplayMetrics()); }Copy the code