一、dpi、dp介绍

sp会随着用户在手机中设置字体大小而改变,而dp不会

ANDROID_MARS学习笔记_S01_004dpi、dp(dip)及计算-LMLPHP

ANDROID_MARS学习笔记_S01_004dpi、dp(dip)及计算-LMLPHP

ANDROID_MARS学习笔记_S01_004dpi、dp(dip)及计算-LMLPHP

二、
1.dpsp_layout.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:textSize="50dp"
android:text="第一个"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0000ff"
android:textSize="50sp"
android:text="第二个"/> </LinearLayout>

2.MainActivity.java

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dpsp_layout);
05-11 18:40