First, DPI, DP Introduction
The SP changes as the user sets the font size on the phone, and the DP does not
Two
1.dpsp_layout.xml
1<?xml version= "1.0" encoding= "Utf-8"?>2<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Android:layout_width= "Match_parent"4android:layout_height= "Match_parent"5android:orientation= "Vertical" >6<TextView7Android:layout_width= "Wrap_content"8android:layout_height= "Wrap_content"9Android:background= "#ff0000"TenAndroid:textsize= "50DP" Oneandroid:text= "First"/> A<TextView -Android:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" theAndroid:background= "#0000ff" -Android:textsize= "50SP" -Android:text= "a second"/> - +</LinearLayout>
2.mainactivity.java
1 @Override 2 protected void onCreate (Bundle savedinstancestate) {3 Super . OnCreate (savedinstancestate); 4 Setcontentview (r.layout.dpsp_layout);
Android_mars study notes _s01_004dpi, DP (DIP) and calculation