相对布局
来源:互联网 发布:网络黑白 花无涯 下载 编辑:程序博客网 时间:2024/04/27 14:30
相对布局由RelativeLayout所代表,相对布局容器内子组件的位置总是相对兄弟组件、父容器来决定的,因此这种布局方式被称为相对布局。
如果A组件的位置是由B组件的位置来决定的,Android要求先定义B组件,再定义A组件。
实例:梅花布局效果
下面是梅花布局效果的界面布局文件:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.example.l2112.xiangduibuju.MainActivity" tools:showIn="@layout/activity_main"> <!-- 定义该组件位于父容器中间 --> <TextView android:id="@+id/view01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="20pt" android:height="20pt" android:background="#00f" android:layout_centerInParent="true" /> <!-- 定义该组件位于view01组件上方 --> <TextView android:id="@+id/view02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="20pt" android:height="20pt" android:background="#00f" android:layout_above="@+id/view01" android:layout_alignLeft="@+id/view01"/> <!-- 定义该组件位于view01组件下方 --> <TextView android:id="@+id/view03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="20pt" android:height="20pt" android:background="#00f" android:layout_below="@+id/view01" android:layout_alignLeft="@+id/view01"/> <!-- 定义该组件位于view01组件左方 --> <TextView android:id="@+id/view04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="20pt" android:height="20pt" android:background="#00f" android:layout_toLeftOf="@+id/view01" android:layout_alignTop="@+id/view01"/> <!-- 定义该组件位于view01组件右方 --> <TextView android:id="@+id/view05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="20pt" android:height="20pt" android:background="#00f" android:layout_toRightOf="@+id/view01" android:layout_alignTop="@+id/view01"/></RelativeLayout>
0 0
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- Android 布局:相对布局
- android相对布局 相对对齐
- 线性布局 相对布局 参数
- 操作系统用C语言模拟进程基于优先级的调度程序
- HttpClient4.5教程-第一章-基础 1.2-1.8
- git cherry-pick简介
- Unity3d 加密 Assembly-CSharp.dll (Android平台) 全记录
- 蓝桥杯_算法训练_ 最大最小公倍数
- 相对布局
- That's My New Blog
- 群体与个体
- 导入第三方工程报错的处理方法
- IOS开发中用到的三方库冲突的解决办法
- LeetCode : Reverse Nodes in k-Group [java]
- Hibernate与Mybatis对比
- 基于Python的流式数据分析平台
- 关于datetime-local与时间戳相互转化