RelativeLayout的基本对齐方式

RelativeLayout的基本对齐方式在 RelativeLayo 相对布局 中 每个组件都可以通过 ID 来指定相对于其它组件或者父组件的位置 1 通过 ID 来指定相对于其它组件的位置 组件之间的相对位置关系设置如下 android layout above 将组件放在指定 ID 组件的上方 android layout below 将组件放在指定 ID 组件的下方 android layout toRig

在RelativeLayout(相对布局)中,每个组件都可以通过ID来指定相对于其它组件或者父组件的位置。

比如以下的layout_relative01.xml文件:

<?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"> <Button  android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" ></Button> <Button  android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button01" android:layout_toRightOf="@id/button01" android:text="按钮2" ></Button> </RelativeLayout>

比如以下的layout_relative02.xml文件:

<?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"> <Button  android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="按钮1" ></Button> <Button  android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button01" android:layout_alignLeft="@id/button01" android:text="按钮2" ></Button> </RelativeLayout>

比如以下的layout_relative03.xml文件:

<?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"> <Button  android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="按钮1" ></Button> <Button  android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button01" android:layout_alignParentLeft="true" android:text="按钮2" ></Button> <Button  android:id="@+id/button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="按钮3" ></Button> </RelativeLayout>

比如以下的layout_relative04.xml文件:

<?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"> <Button  android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="按钮1" ></Button> <Button  android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="按钮2" ></Button> <Button  android:id="@+id/button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="按钮3" ></Button> </RelativeLayout>

5、在相对布局中,如果想固定一个组件的位置,至少要确定组件的”左右”和”上下”两个位置,才可以准确地固定组件位置。

下面的layout_relative05.xml文件:

<?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"> <Button  android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" ></Button> <Button  android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button01" android:text="按钮2" ></Button> <Button  android:id="@+id/button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button01" android:text="按钮3" ></Button> </RelativeLayout>

这时,我们想在按钮3的右边,按钮2的下方,放置一个按钮4,有以下的layout_relative06.xml文件:

<?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"> <Button  android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" ></Button> <Button  android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button01" android:text="按钮2" ></Button> <Button  android:id="@+id/button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button01" android:text="按钮3" ></Button> <Button  android:id="@+id/button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button03" android:text="按钮4" ></Button> </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"> <Button  android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" ></Button> <Button  android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button01" android:text="按钮2" ></Button> <Button  android:id="@+id/button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button01" android:text="按钮3" ></Button> <Button  android:id="@+id/button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button03" android:layout_below="@id/button02" android:text="按钮4" ></Button> </RelativeLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231797.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • unity 三维地球_three.js地球

    unity 三维地球_three.js地球本数字地球全部由作者自由开发完成,未使用任何第三方插件,拥有完全知识产权。2021年10月9日更新已支持离线版高程数据和离线卫星影像数据。2021年1月22日更新全球任意位置模型可正常加载,无变形抖动。2021年12月15日更新日出、日落、大气散射、蓝天效果。说明这个不是GIS软件,是一个带地形的三维地球。2021年11月24日更新支持。2021年11月15日更新支持。,运行流畅无卡顿,占用内存小,最大等级可达到地图20级。在线加载全球地形,也可。…

    2022年9月19日
    2
  • delphi字符串加引号_oracle 单引号

    delphi字符串加引号_oracle 单引号sp_qry.Close;  sp_qry.SQL.Clear;  sp_qry.SQL.Add(‘select*fromitem_infowhereitem_clsno=’+quotedstr(sp_lb.KeyValue));  sp_qry.Open; 用quotedstr()函数不用去算””个数

    2022年10月9日
    2
  • 海思Hi3798MV100机顶盒芯片介绍[通俗易懂]

    海思Hi3798MV100机顶盒芯片介绍[通俗易懂]Hi3798MV100是海思推出的专门针对OTT机顶盒市场的高性价比芯片方案。在码流兼容性、在线视频播放的流畅性、图像质量以及整机性能方面保持业界最好的用户体验。集成四核高性能处理器、内置NEON,其处理性能可以满足各种差异化的业务需求,支持Dolby和DTS音频处理。支持H.265、H.264、AVS+、MVC、MPEG2、MPEG4、VC-1、VP6、VP8等多种格式的高清视频解码和高性…

    2022年6月15日
    88
  • navicat15 密钥自动激活吗_在线激活

    (navicat15 密钥自动激活吗)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年3月30日
    187
  • 代码解读器_网页代码解读

    代码解读器_网页代码解读0写在前面在对STN的原论文进行了翻译、理解后,我打算去github上运行下源码,以加深对ST的理解。毕竟,talkischeap,showmethecode!此外,虽然论文作者发布是tf的源码,但由于我对tensorflow不如pytorch熟稔,因此这里我只看了pytorch官网复现的STN代码。发现写得非常详细,很适合小白入门,因此我放弃了自己解读的机会,打算就搬运一下原教程哈哈。1具体教程注:以下内容均为复制/翻译,不过我在代码上加了点中文注释Spatialtransfor

    2022年10月7日
    3
  • 拉链表的展开算法_如何求展开式的系数

    拉链表的展开算法_如何求展开式的系数在做数据仓库项目的过程中,有时候可能也会根据历史拉链表,展开为每天全量表;相当于一个还原的过程,即构建拉链表的反过程。1、建表及插入测试数据语句 –建表语句–生成EDW_T00_H表(历史拉链表)–CreatetablecreatetableEDW_T00_H(IDVARCHAR2(2)notnull,…

    2022年10月16日
    21

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号