[android] 相对布局和单位简介
2016-02-25 22:43
295 查看
相对布局一般就是控制控件与控件之间的相对位置来定位,如果不设置都是默认以屏幕的左上角的对齐
常见: 位置,对齐
layout_blow 在某控件的下面 layout_above 在某控件的上面
Layout_toRightOf 在某控件的右面 layout_toLeftOf 在某控件的左面
Layout_centerInParent 在父控件的中央
Layout_centerHorizontal 在父控件水平方向剧中
Layout_centerVerital 在父控件垂直方向剧中
与同级别对齐,与父控件对齐
Layout_alignRight 与某控件右边对齐
Layout_alignParentBottom 与父控件底部对齐
Layout_marginLeft layout_marginTop 页边距
Layout_textColor=”#66000000” 支持透明度 argb第一个是透明度
单位:
dp==dip 单位像素密度,在不同分辨率的手机上会自动进行变化,比例显示一致
px 在不同分辨率的手机上会显示一致,因此有时会感觉app的比例不对
sp 实际所代表的大小和dp一致,为了对文字缩放防止锯齿特意制定
测试代码
常见: 位置,对齐
layout_blow 在某控件的下面 layout_above 在某控件的上面
Layout_toRightOf 在某控件的右面 layout_toLeftOf 在某控件的左面
Layout_centerInParent 在父控件的中央
Layout_centerHorizontal 在父控件水平方向剧中
Layout_centerVerital 在父控件垂直方向剧中
与同级别对齐,与父控件对齐
Layout_alignRight 与某控件右边对齐
Layout_alignParentBottom 与父控件底部对齐
Layout_marginLeft layout_marginTop 页边距
Layout_textColor=”#66000000” 支持透明度 argb第一个是透明度
单位:
dp==dip 单位像素密度,在不同分辨率的手机上会自动进行变化,比例显示一致
px 在不同分辨率的手机上会显示一致,因此有时会感觉app的比例不对
sp 实际所代表的大小和dp一致,为了对文字缩放防止锯齿特意制定
测试代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="80dp" tools:context="com.tsh.commonlayout.MainActivity" > <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textColor="#000000" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:text="我是大文本" /> <TextView android:layout_below="@id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textColor="#66000000" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:text="我是小文本" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentRight="true" /> </RelativeLayout>
相关文章推荐
- 【Android开发】Android跨进程通讯(AIDL)官方文档及官方Demo讲解
- Android开发代码规范
- Android IPC机制——Binder详解
- android书籍
- Animation Resources
- Android学习心得第三课
- 第3章Android Dalvik虚拟机 第二节
- 【读书笔记】【Android 开发艺术探索】第1章 Activity 的生命周期和启动模式
- Android开发EditText属性
- Android chrisbanes-PhotoView 使用案例
- Android Volley的网络请求工具
- Android画图最基本的三个对象(Color,Paint,Canvas)
- Android 初探OpenGL ES
- 4种必须知道的Android屏幕自适应解决方案
- Android : Activity 和 TabActivity 共用一个OptionMenu
- 转行自学android,Day6-real编程
- Android SearchView的使用
- 关于Android中图片大小、内存占用与drawable文件夹关系的研究与分析
- Android笔记(一)R文件无法生成
- Android ROM开发(二)——updater-script刷机脚本的讲解和修改以及错误status的修改