kshon学习笔记之android相对布局

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kshon/article/details/77855202

在andorid的几种布局中,相对布局RelativeLayout还是挺好用的,首先介绍一下相关的属性吧。

取值只能为Boolean的属性:

layout_centerHorizontal  控制组件是否位于布局容器的水平居中位置

layout_centerVertical      控制组件是否位于布局容器的垂直居中位置

layout_Inparent               控制组件是否位于布局容器的中央位置

layout_alignParentBottom  控制组件是否与布局容器的底端对齐

layout_alignParentTop        控制组件是否与布局容器的顶端对齐

layout_alignParentLeft        控制组件是否与布局容器的左边对齐

layout_alignParentRight     控制组件是否与布局容器的右边对齐

取值为其他组件ID的属性:

layout_toRightOf    控制组件位于给出ID组件的右边

layout_toLeftOf      控制组件位于给出ID组件的左边

layout_above         控制组件位于给出ID组件的上方

layout_below         控制组件位于给出ID组件的下方

layout_alignRight  控制组件与给出ID组件的右边界对齐

layout_alignLeft    控制组件与给出ID组件的左边界对齐

layout_alignTop    控制组件与给出ID组件的上边界对齐

layout_alignBottom 控制组件与给出ID组件的下边界对齐


示例:

<?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">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/edit1"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/cancel"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/edit1"
        android:layout_marginRight="20dp"
        android:text="取消"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/cancel"
        android:layout_alignTop="@+id/cancel"
        android:text="确定"/>

</RelativeLayout>



猜你喜欢

转载自blog.csdn.net/kshon/article/details/77855202