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

一、dpi、dp介绍

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

二、
1.dpsp_layout.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6     <TextView 
 7         android:layout_width="wrap_content"
 8         android:layout_height="wrap_content"
 9         android:background="#ff0000"
10         android:textSize="50dp"
11         android:text="第一个"/>
12     <TextView 
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:background="#0000ff"
16         android:textSize="50sp"
17         android:text="第二个"/>
18 
19 </LinearLayout>


2.MainActivity.java

1     @Override
2     protected void onCreate(Bundle savedInstanceState) {
3         super.onCreate(savedInstanceState);
4         setContentView(R.layout.dpsp_layout);
原文地址:https://www.cnblogs.com/shamgod/p/5184983.html