android 尺寸单位介绍(dp,sp,px)

版权声明:虽然我很菜,但我在努力! https://blog.csdn.net/qq_39331713/article/details/82900404

 

sp与dp的区别

下面我们进行一下实验: textSize的单位分别设置为sp和dp,然后改变系统字体大小

<?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="200dp"
        android:layout_height="wrap_content"
        android:text="尚硅谷科技"
        android:background="#ff0000"
        android:textSize="20sp"/>
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="200px"
        android:layout_height="wrap_content"
        android:text="尚硅谷科技"
        android:background="#00ff00"
        android:textSize="20dp"/>
 
</LinearLayout>

结果显示 

总结

猜你喜欢

转载自blog.csdn.net/qq_39331713/article/details/82900404
今日推荐