您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
13_android界面大小显示的单位
发布时间:2021-02-04 18:36:46编辑:雪饮阅读()
px
控件的大小可以像前面一样用dip做为单位也可以用网页中最常用的px做为单位
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="30px"
android:layout_height="wrap_content"
android:text="我是文本"/>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="30px"
android:layout_height="wrap_content"
android:text="我是文本"/>
</FrameLayout>
Dip与px的区别
那么dip与px是什么区别呢?话说px就是像素,那么不同设备下相同px则展现的长度在肉眼所看到的是不同的,就比如说1像素在320x240设备上可能就是很长的长度,因为分辨率比较小,密度稀疏。而在640x320分辨率的设备(该设备和320x240分辨率的设备外观上一样大)上由于相同的屏幕尺寸,而本设备的分辨率更大,所以1px表达的长度由于分辨率大导致密度大,所以1px就显示的比刚才320x240设备上同样的1像素小了很多。
而dip则相当于一个比例,所以不会出现该问题。
Sp
Sp单位一般用于字体大小等的设置
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是文本"
android:textSize="50sp"
/>
</FrameLayout>
关键字词:android,单位
上一篇:12_常用的一些布局简洁