相对布局由于属性比较多,所以用起来有些费力,但灵活性较其他布局方法好,所以掌握好相对布局将会非常有用。先看等一个例子

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent">
  5. <TextView
  6. android:id="@+id/label"
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="Type here:"/>
  10. <EditText
  11. android:id="@+id/entry"
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content"
  14. android:background="@android:drawable/editbox_background"
  15. android:layout_below="@id/label"/>
  16. <Button
  17. android:id="@+id/ok"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:layout_below="@id/entry"
  21. android:layout_alignParentRight="true"
  22. android:layout_marginLeft="10dip"
  23. android:text="OK" />
  24. <Button
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:layout_toLeftOf="@id/ok"
  28. android:layout_alignTop="@id/ok"
  29. android:text="Cancel" />
  30. </RelativeLayout>

这是很常见的布局内容,讲解如下:

  1. android:layout_below="@id/label"/>

将当前控件放置于id为label 的控件下方

使当前控件的右端和父控件的右端对齐。这里属性值只能为true或false,默认false。

使当前控件左边空出相应的空间。

使当前控件置于id为ok的控件的左边。

使当前控件与id控件的上端对齐。

至此,我们已经发现,其属性之繁多。下面简单归纳一下:
第一类:属性值为true或false
*android:layout_centerHrizontal
*android:layout_centerVertical
*android:layout_centerInparent
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
第二类:属性值必须为id的引用名“@id/id-name”
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
第三类:属性值为具体的像素值,如30dip,40px
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop

再看第二个例子:

转载于:https://blog.51cto.com/zuiniuwang/720150

Android相对属性布局总结相关推荐

  1. Android 控件布局常用属性

    <!--单个控件经常用到 android:id -- 为控件指定相应的ID android:text -- 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符 ...

  2. Android控件布局属性全解(一看就会)

    Android有太多的布局属性繁琐又晦涩,下面结合了网上很多资料汇总. 内容太多,可以Ctrl+F进行搜索 第一类:属性值为true或false android:layout_centerHrizon ...

  3. 【Android布局】在程序中设置android:gravity 和 android:layout_Gravity属性

    在进行UI布局的时候,可能常常会用到 android:gravity  和 android:layout_Gravity 这两个属性. 关于这两个属性的差别,网上已经有许多人进行了说明,这边再简单说一 ...

  4. Android应用开发(1)---Android五大UI布局的特有属性

    Android五大UI布局的特有属性 Android五大UI布局 1. LinearLayout 线性布局 2. RelativeLayout 相对布局 3. FrameLayout 帧布局,空白布局 ...

  5. Android:安卓线性布局(属性)

    安卓线性布局(属性) 安卓六大布局: AbsoluteLayout  绝对布局(已过期,不建议使用) RelativeLayout    相对布局 LinearLayout       线性布局 Fr ...

  6. [Android]Android布局文件中的android:id=@*属性使用方法汇总以及介绍

    由于项目需要进行Android开发,因此一边开发,一边查阅资料,一边总结了Android布局文件中android:id="@*"属性的使用方法汇总以及介绍.id资源的引用 andr ...

  7. Android Studio 线性布局Linearlayout的控件位置控制l属性Layout_margin失效问题解决

    Android Studio 线性布局Linearlayout的控件位置控制l属性Layout_margin失效问题解决 问题:如layout_marginRight ="50dp" ...

  8. Android UI系列 - 布局 - 属性详解

    本文转自:http://www.cnblogs.com/chiao/archive/2011/08/25/2153652.html LinearLayout布局: 线性版面配置,在这个标签中,所有元件 ...

  9. android textview layoutparams,Android动态设置布局的LayoutParams属性总遇到造型异常

    Android动态设置布局的setLayoutParams()属性总遇到造型异常问题 android:id="@+id/introduce" android:layout_widt ...

  10. android linearlayout属性大全,Android中LinearLayout布局的常用属性总结读书笔记

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? 原CSDN博客已弃用,文章会逐渐迁移过来. 应朋友们反馈的Android基础薄弱的问题,决定出一套Android基础教程 ...

最新文章

  1. # vmware异常关机后,虚拟系统无法启动的解决办法
  2. Python计算机视觉:第八章 图像类容分类
  3. GFS架构启示 | Google File System
  4. ORACLE TEXT LEXER PREFERENCE(四)
  5. iis管理常用命令 创建IIS站点 应用应用程序 及虚拟目录
  6. java 方法 示例_Java集合syncedSortedSet()方法与示例
  7. fft的c语言和matlab对比_傅里叶级数(FS)、傅里叶变换(FT)快速傅里叶变换(FFT)及量子傅里叶变换(QFT)之间推导关系...
  8. TDL(HDU-6641)
  9. mysql5.7.21压缩版_mysql5.7.21解压版安装配置图文
  10. thinkphp LoginAction.class.php 登录模块
  11. PDF编辑(PDF替换指定页)---亲测实用有效!!!
  12. C语言万年历设计制作
  13. android 地址选择下载,选择走开下载-选择走开(吃饭位置选择)下载v1.0.4 安卓版-西西软件下载...
  14. 基频,倍频,基波,谐波,基音,泛音
  15. 手机访问WEB项目图片404
  16. 多语言 - 国际化处理 上
  17. 2022年全球及中国场地电动车行业市场规模竞争格局研究预测及市场发展趋势分析预测
  18. eu.org免费域名白嫖教程以及避坑
  19. Talib常用函数图像形态识别
  20. 【校队+实验班】萌新训练赛【2】

热门文章

  1. 自动生成 Makefile 的全过程详解! automake/autoconf 入门
  2. ScrollView不设置contentSize属性依然也可以作为底层滚动View(使用masonry设置scrollView的contentSize)...
  3. Hive学习笔记(二)——数据模型
  4. POJ 2068 NIm (dp博弈,每个人都有特定的取最大值)
  5. 第二次作业+105032014049
  6. Linux或Linux虚拟机桥接模式使用Python2认证Drcom
  7. VC中Radio控件的用法
  8. jQuery学习笔记:文档处理
  9. HomeBrew太慢,如何替换默认HomeBrew源,使用阿里云的源
  10. golang格式化输出---fmt包用法详解