Android布局之相对布局RelativeLayout

一、RelativeLayout(相对布局)概述

  RelativeLayout是相对布局控件,它包含的子控件将以控件之间的相对位置或者子类控件相对父类容器的位置的方式排列

二、RelativeLayout(相对布局)的属性

  1、子类控件在RelativeLayout中常用到的属性(相对于父容器的一个位置)

    android:layout_alignParentLeft = "true"  子类控件相对当前父类容器靠左边(默认)

    android:layout_alignParentTop = "true"  子类控件相对父容器靠上边

    android:layout_alignParentRight="true"    子类控件相对父容器靠右边
    android:layout_alignParentBottom="true"    子类控件相对父容器靠下边

    android:layout_margin="20dp"      子类控件距离父类容器四边的距离

    android:layout_marginLeft = "41dp"    子类控件距离父类容器左边的距离

    android:layout_marginTop = "41dp"    子类控件距离父类容器上边的距离

    android:layout_marginBottom = "41dp"    子类控件距离父类容器下边的距离

      android:layout_marginLeft = "41dp"    子类控件距离父类容器左边的距离

     android:layout_marginRight = "41dp"    子类控件距离父类容器右边边的距离

    android:layout_centerInParent = "true"   子类控件相对父容器即水平居中有垂直居中

    android:layout_centerHorizontal = "true"   子类控件相对父容器水平居中 

    android:layout_centerVertical = "true"    子类控件相对父容器垂直居中

  2、子类控件相对于子类控件的一个位置

    android:layout_below = "@+id/button1"    该控件位于给定id控件的底部

    android:layout_toRightOf = "@+id/button1"     该控件位于给定id控件的右边

    android:layout_above = "@+id/button1"     该控件位于给定id控件的上面

    android:layout_toLeftOf = "@+id/button1"     该控件位于给定id控件的左边

    android:layout_alignBaseline = "@+id/button1"    该控件的内容与给定id控件的内容在一条线上

    android:layout_alignBottom    该控件的底部边缘与给定id控件的底部边缘对齐

    android:layout_alignLeft    该控件的底部边缘与给定id控件的左部边缘对齐

    android:layout_alignRight    该控件的底部边缘与给定id控件的右部边缘对齐

    android:layout_alignTop    该控件的底部边缘与给定id控件的顶部边缘对齐

、RelativeLayout(相对布局)使用例子

    在商城中通常会有这样的布局,一个图片  右边有几条信息

     

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="26dp"
        android:layout_marginTop="26dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView1"
        android:layout_marginLeft="24dp"
        android:layout_toRightOf="@+id/imageView1"
        android:text="狗不理包子" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:text="20元" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignLeft="@+id/textView2"
        android:text="有贵又不好吃" />

</RelativeLayout>

  

时间: 2024-08-07 02:40:22

Android布局之相对布局RelativeLayout的相关文章

Android五种布局方式——LinearLayout、RelativeLayout、TableLayout....(四)

Android五种布局方式--LinearLayout.RelativeLayout .TableLayout.... Android使用XML声明界面布局 将程序的表现层和控制层分离 修改用户界面时,无需更改程序的源代码 可视化工具设计用户界面 Android五种布局方式 LinearLayout线性布局 AbsoluteLayout坐标布局 RelativeLayout相对布局 FrameLayout帧布局 TableLayout表格布局 GridLayout 1.LinearLayout线

浅谈Android五大布局(二)——RelativeLayout和TableLayout

在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局RelativeLayout(相对布局)和TableLayout(表格布局)相对之前布局结构稍显复杂一点,所以这里另起篇幅进行介绍. RelativeLayout: RelativeLayout按照各子元素之间的位置关系完成布局.在此布局中的子元素里与位置相关的属性将生效.例如android:layout_be

Android五大布局之一相对布局(RelativeLayout)

一.RelativeLayout(相对布局)重点: 在没有指点位置的情况下,RelativeLayout会默认生成控件的位置是左上角 所以必须需要添加属性android:id="@+id/name"定义控件的名称,其他控件就可以通过@id/name找到它进行相对布局 二.RelativeLayout(相对布局)相关的属性: 三.例子 1.首先先创建一个RelativeLayout的XML文件 代码如下: 1 <?xml version="1.0" encodi

浅谈Android五大布局(二)——RelativeLayout和TableLayout【转】

http://www.cnblogs.com/wisekingokok/archive/2011/08/24/2152004.html 在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局RelativeLayout(相对布局)和TableLayout(表格布局)相对之前布局结构稍显复杂一点,所以这里另起篇幅进行介绍. RelativeLayout: Relat

Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布局,AbsoluteLayout绝对布局,RelativeLayout相对布局

在Android中提供了几个常用布局: LinearLayout线性布局 RelativeLayout相对布局 FrameLayout帧布局 AbsoluteLayout绝对布局 TableLayout表格布局 GridLayout网格布局 TableLayout表格布局 TableLayout的介绍 TableLayout是将子类向分别排列成行和列的布局视图容器,TableLayout是由许多TableRow对象组成的,表格布局以行列的形式管理子控件,每一个单元是一个TableRow或者Vie

android界面设计之布局管理

谈到android界面设计,各种布局样式不得不提!传统的布局方式有6种,我们会一一介绍. 在android studio2.2版本之后出现了一款超棒的布局方式,真正意义上的所见即所得,后面我们也会讲到! 1.LinearLayout:线性布局:线性布局又有两种,"垂直布局"和"水平布局". 垂直布局每一行只能有一个控件(自己嵌套的不算): 水平布局只有一行,所有的控件依次从左向右排列: linearLayout中有一个重要的属性 android:layout_wei

Android开发-之五大布局

在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然布局方式不一样应用的地方也不一样,当然了有的布局方式也是可以相互转换和嵌套使用的.它们都各有各的优缺点,具体页面要怎么布局还是得看开发需求,但是用的最多的还是相对布局.线性布局以及相对布局和线性布局的嵌套使用.当然,我说的是安卓,并没有指定是安卓手机,比如平板.智能家居(电视...)很多都是Andr

android中的五大布局和过程流向

1.首先说明android中的五大布局: 1.绝对布局:AbsoluteLayout(按照绝对坐标来布局组件) 2.相对布局:RelativeLayout(相对其它组件的布局方式) 3.线性布局:LinearLayout(按照垂直或者水平方向布局的组件,通                        过"android:orientation"属性可以设置线性布局的方向. 属性值有垂直(vertical)和水平(horizontal)两种. android:orientation:可

Android仿微信UI布局视图(圆角布局的实现)

圆角按钮,或布局可以在xml文件中实现,但也可以使用图片直接达到所需的效果,以前版本的微信就使用了这种方法. 实现效果图:    不得不说,这种做法还是比较方便的. 源代码: MainActivity(没写任何代码,效果全在布局文件中实现): package com.android_settings; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity

android界面设计之布局

一.线性布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orie