关于dp、px、sp以及线性布局、相对布局
来源:互联网 发布:校音器软件 编辑:程序博客网 时间:2024/05/22 03:12
(1)px (pixels)(像素):屏幕上的点 ,与密度相关。密度大了,单位面积上的px会比较多。
(2)dip或dp(与密度无关的像素)。这个和设备硬件有关,为了支持WVGA、HVGA和QVGA 5进制空间推荐使用这个。一种基于屏幕密度的抽象单位。设置一些view的宽高可以用这个,一般情况下,在不同分辨率,都不会有缩放的感觉。如果用px的话,320px占满HVGA的宽度,到WVGA上就只能占一半不到的屏幕了,那一定不是你想要的。
(3)sp(与刻度无关的像素)放大像素– 主要处理字体的大小。
线性布局(LinearLayout):在该标签下的所有子元素会根据orientation属性的值来决定是按行或者是按列来逐个显示。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test" />
</LinearLayout>
相对布局:则是根据控件的相对位置而言,比如居于按钮的左侧或者右侧。
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button1"
android:layout_alignTop="@id/button1"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/app_name" />
</RelativeLayout>
仅仅使用dp和sp不能完美适应屏幕,当换到不同尺寸的屏幕时还是会变形。
- 关于dp、px、sp以及线性布局、相对布局
- 关于Android布局中px,pt,dp,sp的总结
- android布局单位dip dp sp px
- Android布局单位及分辨率(dip,dp,sp,px)
- android 的布局单位 dip dp sp px总结
- Android布局单位及分辨率(dip,dp,sp,px)
- 安卓-界面布局单位dp,sp,px之比较
- 线性布局 相对布局 参数
- 布局——线性布局、相对布局
- 关于Android setTextSize() 以及 px dip/dp sp的说明
- andriodUI 相对·线性布局的使用以及程序国际化
- 线性布局和相对布局的知识点
- 线性布局和相对布局小Demo
- android 中的线性布局与相对布局
- Android 线性布局和相对布局
- 线性布局 相对布局 属性介绍
- Android相对布局和线性布局
- Android相对布局和线性布局
- AngularJS模块
- 从高考到吃“软”饭
- easyui datagrid 前台分页的实现java采用的版本
- vpn原理-pptp,l2tp,openvpn
- java多线程技术
- 关于dp、px、sp以及线性布局、相对布局
- 无符号整形求bit位数字的巧妙方法------右移模2
- linux创建swap交换分区
- 4.Go语言变量
- Linux文本处理三剑客之sed
- 关于springmvc的配置问题
- 微信开发 获取用户信息两个接口
- redis 中 set 和 hset 有什么不同,什么时候使用 hset 什么时候使用set?
- java.lang.NoClassDefFoundError