文章目录
相对布局RelativeLayout
输入姓名
常见相对布局基本属性:
-
gravity :设置该布局容器内各子组件的对齐方式
-
ignoreGravity:设置哪个组件不受gravity属性的影响
根据父容器定位
- layout_alignParentLeft 左对齐
- layout_alignParentRight 右对齐
- layout_alignParentTop 顶部对齐
- layout_centerVertical 垂直居中
- layout_centerInparent 中间位置
- layout_alignParentBottom 底部对齐
根据兄弟组件定位
-
android:layout_toLeftOf 参考组件的左边
-
android:layout_toRightOf 参考组件的右边
-
android:layout_above 参考组件的上方
-
android:layout_below 参考组件的下方
-
android:layout_alignTop 对齐参考组件的上边界
-
android:layout_alignBottom 对齐参考组件的下边界
-
android:layout_alignLeft 对齐参考组件的左边界
-
android:layout_alignRight 对齐参考组件的右边界
4、填充(padding)
-
android:padding 上下左右填充边距
-
paddingLeft 左边填充边距
-
paddingRight 右边填充边距
-
paddingTop 上方填充边距
-
paddingBottom 下方填充边距
创建安卓应用
编写主布局资源文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tool