I occured a problem when using RadioButton. The RadioButton's layout_height must be 15dp, and the offical design guide says that 1sp is 1dp, so I set the font size to 1sp, but the TextView's layout_height is a little bigger than 15dp. It seems that when the font size is 15sp, the layout_height of the TextView is 18dp. So what's the relationship between the font size and the layout_height?
First thing I wanted to mention is the font-padding, which is by default included into the TextView
size. So to make TextView
's size closer to the size of the text itself - specify android:includeFontPadding="false"
Now, if you compare View
with layout_height
equals to 20 sp and TextView
with TextSize
20sp - they are going to be almost equally high.
(There's small difference, as text might contain very high letter like "Å" or the letter like "y" which goes below the baseline)
About sp vs dp.
Scale-independent Pixels - This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.
It depends on how big is your font (Settings->Accessibility->Enable/Disable Large Text). You can change it and see the effect.
Hope, it helps.
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