.Net程序猿玩转Android开发---(7)相对布局RelativeLayout
能够设置控件与父控件的位置,控件与控件之间的位置。
1. 控件与父容器位置属性
android:layout_alignParentLeft="true" 子控件相对于父容器靠左边
android:layout_alignParentTop="true"
子控件相对于父容器靠 上边
android:layout_marginTop="50dp"
子控件与父容器上边距距离
android:layout_marginBottom="50dp"
子控件与父容器下边距距离
android:layout_marginRight="50dp"
子控件与父容器右边距距离
android:layout_marginLeft="50dp"
子控件与父容器左边距距离
android:layout_centerInParent="true"//子控件在父容器中居中显示
android:layout_centerHorizontal="true" //子控件在父容器中水平居中
android:layout_centerVertical="true" 子控件在父容器中垂直居中
以下的演示样例展示下相对于父容器的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="相对父easy布局"
android:background="#97FFFF" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:layout_marginRight="50dp" /> </RelativeLayout>
2.控件与控件间位置属性
控件与控件之间的位置属性,是指控件与相邻控件的位置设置,主要有下面属性
android:layout_below="@+id/textView1" 该控件位于指定控件的下方
android:layout_toLeftOf="@+id/textView1" 控件位于指定控件的左側
android:layout_toRightOf="@+id/textView1" 控件位于指定控件的右側
android:layout_above="@+id/textView1" 控件位于指定控件的上面
android:layout_alignBaseline="" 该控件的内容与指定控件的内容在同一直线上
android:layout_alignBottom=""该控件的底部与指定控件的底部对齐
android:layout_alignLeft="" 该控件与指定控件左側对齐
android:layout_alignRight="" 该控件与指定控件右側对齐
android:layout_alignTop="" 该控件与指定控件的顶部对齐

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="110dp"
android:id="@+id/layone"
> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFD700"
android:text="标签1" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:background="#FF0000"
android:text="标签2" />
</RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_below="@+id/layone"
> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#EE9572"
android:text="标签3" /> <TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_toRightOf="@+id/textView3"
android:background="#CDAA7D" android:text="标签4" />
</RelativeLayout> </RelativeLayout>
3.商品列表演示样例
以下我们展示一个商品列表,使用RelativeLayout来展示,效果图例如以下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:id="@+id/layout1"
> <ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@raw/pad" /> <TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="商品名称:IPAD AIR" /> <TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/imageView1"
android:layout_below="@+id/textView1"
android:text="商品价格:$19" /> <TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/imageView1"
android:layout_below="@+id/textView2"
android:text="商品颜色:白色" /> </RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#CDAA7D"
android:layout_below="@+id/layout1"
android:id="@+id/layout2"
>
</RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_below="@+id/layout2"
android:id="@+id/layout3"
> <ImageView
android:id="@+id/imageView2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@raw/pad" /> <TextView
android:id="@+id/textView4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView2"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/imageView2"
android:text="商品名称:IPAD AIR" /> <TextView
android:id="@+id/textView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/imageView2"
android:layout_below="@+id/textView4"
android:text="商品价格:$19" /> <TextView
android:id="@+id/textView6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/imageView2"
android:layout_below="@+id/textView5"
android:text="商品颜色:白色" /> </RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#CDAA7D"
android:layout_below="@+id/layout3"
>
</RelativeLayout> </RelativeLayout>
.Net程序猿玩转Android开发---(7)相对布局RelativeLayout的更多相关文章
- .Net程序猿玩转Android开发---(6)线性布局LinearLayout
LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...
- .Net程序猿玩转Android开发---(8)表格布局TableLayout
表格布局TableLayout是Android中比較经常使用的一个布局控件,既然是表格,肯定有行和列,TableLayout中的行有TableRow组成.列依据每行控件的数量来确定 假如第一行有3个控 ...
- .Net程序猿玩转Android开发---(11)页面跳转
在不论什么程序开发中,都会遇到页面之间跳转的情况,Android开发也不例外.这一节,我们来认识下Android项目中如何进行页面跳转.页面跳转分为有參数和无參数页面跳转,已经接受还有一个页面的返回值 ...
- .Net程序猿玩转Android开发---(3)登陆页面布局
这一节我们来看看登陆页面如何布局.对于刚接触到Android开发的童鞋来说.Android的布局感觉比較棘手.须要结合各种属性进行设置,接下来我们由点入面来 了解安卓中页面如何布局,登陆页面非常eas ...
- .Net程序员玩转Android开发--ListView单击事件
public class ListViewClickActivity extends Activity { private ListView lv; SimpleAdap ...
- .Net程序员玩转Android系列之一~Java快速入门
前言 前段时间受公司业务发展需要,探索性进入Android开发领域.一切从零开始,java基础,Java进阶,Android框架学习,Eclipse熟悉,最终到第一个即时通讯App完成,历经一个月的时 ...
- 作为一个程序员怎么通过android开发赚钱
上面是一个程序员通过Android开发每天的收入,信则有! 自己学安卓差不多,有一年了.我本来是从事javaweb开发的,可能学习安卓上手会快点.其实安卓没有那难 .首先开发安卓程序,要有一个,开 ...
- Android开发-之五大布局
在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...
- Android开发5大布局方式详解
Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...
随机推荐
- OpenStack使用Bosh部署CloudFoundry(一)—准备OpenStack环境
版本说明: CloudFoundry:V2版本 OpenStack:Folsom或者Grizzly版本 本篇文章采用OpenStack Folsom+nova-network的OpenStack环境, ...
- MongoDB学习笔记(四) 用MongoDB的文档结构描述数据关系
MongoDB的集合(collection)可以看做关系型数据库的表,文档对象(document)可以看做关系型数据库的一条记录.但两者并不完全对等.表的结构是固定的,MongoDB集合并没有这个约束 ...
- Delphi 模拟网站验证码(酷,把随机文字写道图片上)
function TfrmLabelPages.PwdImg(img: Timage): string; var I,j,k: Integer; vPoint: TPoint; vLeft: Inte ...
- 与众不同 windows phone (15) - Media(媒体)之后台播放音频
原文:与众不同 windows phone (15) - Media(媒体)之后台播放音频 [索引页][源码下载] 与众不同 windows phone (15) - Media(媒体)之后台播放音频 ...
- 纯JS实现的3D标签云,不依赖不论什么第三方库,支持移动页面
<span style="font-family: Arial, Helvetica, sans-serif;"><!DOCTYPE html PUBLIC &q ...
- Swift - 使用网格(UICollectionView)进行流布局
一.网格UICollectionView最典型的例子是iBooks.其主要属性如下: 1,layout 该属性表示布局方式,有Flow.Custom两种布局方式.默认是Flow流式布局. 2,Acce ...
- Redis Destop Manager不能访问虚拟机
虚拟机centOS中安装Redis,主机Redis Destop Manager不能访问虚拟机Redis server的解决方案 今天在学些redis的时候碰到个问题,发现主机Redis Destop ...
- Qt Windows下开机自动启动自己的程序
源地址:http://blog.csdn.net/chrisfxs/article/details/13279491 版权声明:本文为博主原创文章,未经博主允许不得转载. void Widget::R ...
- sqlserver 操作技巧
1.将不同库中的一张表数据导入到另外一张表中去 ① 两张表多存在实体,两表的字段相同,字段的顺序相同的话. insert into 表B select * from 表A ② 两张表多存在实体,两表的 ...
- c中使用malloc动态申请二维数组
前言 今天写代码的时候,想要动态的申请一个二维数组空间,思索了一段时间才写出来,这里记录一下吧,以后就不至于再浪费时间了.下面以申请int型数组作为例子: 申请一维数组 一维数组的数组名可以看成数组起 ...