您的位置:首页 > 移动开发 > Android开发

[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一致,为了对文字缩放防止锯齿特意制定

测试代码

<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: