首页 > 移动平台 > 详细

[android] 相对布局和单位简介

时间:2016-02-26 00:25:53      阅读:185      评论:0      收藏:0      [点我收藏+]

相对布局一般就是控制控件与控件之间的相对位置来定位,如果不设置都是默认以屏幕的左上角的对齐

常见: 位置,对齐

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] 相对布局和单位简介

原文:http://www.cnblogs.com/taoshihan/p/5218664.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!