From the start of the Android program, I was told that the common sense
1. Length width of the value to use the DP as a unit into the Dimens.xml file
2. The value of the font size to use the SP as a unit, also into the Dimens.xml file
Then, there is no then, as if the subtext is that, you remember to use on the line.
One day, when we accidentally put the font into a DP, it can work, and the effect of the same as the SP.
At this time, began to doubt, what is the difference between DP and SP what is different?
Let's do a simple sample verification, like the following, a layout code
<textview
android:layout_width= "wrap_content"
android:layout_height= "Wrap_content"
android: Textsize= "18SP"
android:text= "Hello world! in SP"/>
<textview android:layout_width=
"Wrap_ Content "
android:layout_height=" wrap_content "
android:textsize=" 18DP "
android:text=" Hello world! in DP "/>
The effect is this way.
However, when we enter the system settings to modify the font for a large hour
Again into the previous interface, found something different.
From this perspective
Using the SP as the font size unit changes with the font size of the system
And the DP as the unit does not.
About the SP, the document is described as:
Scale-independent Pixels–this is like the DP unit, but it's also scaled by the user ' s font size preference. It is recommend to specifying font sizes, so they'll be adjusted for both the screen density and the User ' s preference.
The general meaning of
The SP is affected by the screen density, but also by the font size of the user
In general, it is recommended that you use an SP to follow user font size settings
So normally, we recommend using an SP as a font unit, and you can use a DP unless there are special situations where you don't want to follow the system font.
Thank you for reading, I hope to help you, thank you for your support for this site!