RelativeLayout是一个相对布局类。

首先RelativeLayout是一个容器,它里边的元素,如Buttonbutton等的位置是依照相对位置来计算的,比如,有两个Buttonbutton都布局在一个RelativeLayout里边。我们能够定义第二个Button在第一个Button的上边或者是右边。但究竟第二个Button在什么位置呢,它还是依赖于第一个Button的位置。需要注意的是。出于性能上的考虑。对于相对布局的精确位置的计算仅仅会运行一次。所以。假设一个可视化组件B依赖A,那么必需要让A出如今B的前边。





实例:LayoutDemo

执行效果:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSGFuVGFuZ1NvbmdNaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

代码清单:

布局文件:relative_layout.xml

<?

xml version="1.0" encoding="utf-8"?

>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
>
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入username:"
/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/label"
/>
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="取消"
/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cancel"
android:layout_alignTop="@id/cancel"
android:text="确定"
/> </RelativeLayout>

Java源码文件:RelativeLayoutActivity.java

package com.rainsong.layoutdemo;

import android.app.Activity;
import android.os.Bundle; public class RelativeLayoutActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.relative_layout);
}
}

API知识点



android:id                  定义组件的id

android:layout_width        定义组件的宽度

android:layout_height       定义组件的高度

android:padding             填充

android:layout_below        将当前组件放置于指定组件的下方

android:layout_alignParentRight 和父容器的右边齐平

android:layout_marginLeft   右边距

android:layout_toLeftOf     设置此组件在指定组件的左边

android:layout_alignTop     设置此组件和指定组件高度齐平

Android UI布局之RelativeLayout的更多相关文章

  1. Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)

    首先介绍常用布局类 FrameLayout 最简单的布局管理器. 这个布局管理类有几个特性: 添加组件默认在左上角的. 如果添加多个组件会叠加到一起,并且都在左上角.(可以通过一gravity属性改变 ...

  2. 让我们创建屏幕- Android UI布局和控件

    下载LifeCycleTest.zip - 278.9 KB 下载ViewAndLayoutLessons_-_Base.zip - 1.2 MB 下载ViewAndLayoutLessons_-_C ...

  3. android 基本布局(RelativeLayout、TableLayout等)使用方法及各种属性

        本文介绍 Android 界面开发中最基本的四种布局LinearLayout.RelativeLayout.FrameLayout.TableLayout 的使用方法及这四种布局中常用的属性. ...

  4. Android——android相对布局(RelativeLayout)及属性

    RelativeLayout布局 android:layout_marginTop="25dip" //顶部距离 android:gravity="left" ...

  5. [Irving]Android 常用布局之RelativeLayout

    RelativeLayout相对布局 相对布局 RelativeLayout 允许子元素指定它们相对于其父元素或兄弟元素的位置,这是实际布局中最常用的布局方式之一. 它灵活性大很多,当然属性也多,操作 ...

  6. Android UI布局之LinearLayout

    LinearLayout是Android中最经常使用的布局之中的一个.它将自己包括的子元素依照一个方向进行排列.方向有两种,水平或者竖直.这个方向能够通过设置android:orientation=& ...

  7. 【Android UI】使用RelativeLayout与TableLayout实现登录界面

    使用RelativeLayout与TableLayout分别实现两种登录界面,学习RelativeLayout布局 中如何对齐与调整组件相对位置,使用TableLayout实现登录界面,学习如何设置列 ...

  8. Android -- UI布局管理,相对布局,线性布局,表格布局,绝对布局,帧布局

    1. 相对布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  9. Android UI布局之FrameLayout

    一个FrameLayout对象就好比一块屏幕上提前预定好的空白区域.然后能够填充一些元素到里边.例如说一张图片等.须要注意的是,全部的元素都被放置在FrameLayout区域最左边上的区域.并且无法为 ...

随机推荐

  1. 添加 vip

    两台机器:172.16.91.101 172.16.91.107 在91.101上增加虚拟ip,92网段的 ifconfig eth0:1 172.16.92.2 netmask 255.255.25 ...

  2. WinPython

    WinPython   http://winpython.github.io/

  3. 各种Oracle索引类型介绍

    逻辑上:Single column 单行索引Concatenated 多行索引Unique 唯一索引NonUnique 非唯一索引Function-based函数索引Domain 域索引 物理上:Pa ...

  4. 学习shader之前必须知道的东西之计算机图形学-渲染管线

    引言 shader到底是干什么用的?shader的工作原理是什么? 其实当我们对这个问题还很懵懂的时候,就已经开始急不可耐的要四处搜寻有关shader的资料,恨不得立刻上手写一个出来.但看了一些资料甚 ...

  5. Java全栈程序员之01:做个Linux下的程序猿

    Windows10正在成为史上口碑最差的Windows系统 (图侵删) 我曾经花了数次1小时去寻找解决方案去关闭自动更新,包括停掉服务.修改注册表等等.但是都没有成功. 微软自身是知道这个问题的,但就 ...

  6. C# 获取文件名及扩展名【转】

    https://www.cnblogs.com/libushuang/p/5794976.html C# 获取文件名及扩展名 string aFirstName = aFile.Substring(a ...

  7. shell模板变量替换

    我们经常使用一些模板语言来处理一些变量替换.比如jsp,php,velocity,freemarker,thymeleaf等.那对于shell来说,应该怎样替换变量呢.有一种很简单的办法可以做到. 先 ...

  8. 常见的机器学习&数据挖掘知识点

    原文:http://blog.csdn.net/heyongluoyao8/article/details/47840255 常见的机器学习&数据挖掘知识点 转载请说明出处 Basis(基础) ...

  9. Node.js Cheerio parser breaks UTF-8 encoding

    From: https://stackoverflow.com/questions/31574127/node-js-cheerio-parser-breaks-utf-8-encoding [问题] ...

  10. GDAL对TIF创建内建金字塔一个问题

    gdalwarp输出tif图像的时候,默认如果没有使用BIGTIFF=YES选项,则会根据输出影像的大小进行判断,低于4G则不适用bigtiff格式. 对于非bigtiff图像,如果这时候使用gdal ...