04. Relative Layout of Android Development Foundation

Relative Layout of Android Development Foundation

Relative layout, that is, the layout with reference objects.When we were young, we went to school, between classmates and classmates, who was on whose right and who was on whose left!This is for whom!The relative layout in Android is the same!

There are two kinds, one is relative to the father, that is, the parent control, and the other is relative to the sibling control.

Relative layout relative to parent control

<?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:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Middle"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Upper Right Corner"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="Lower Right Corner"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Top left corner"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Lower left quarter"/>
</RelativeLayout>

Relative Layout Relative to Peer Control

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

    <!--This is the middle part-->
    <Button
        android:id="@+id/center_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Determine"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@id/center_button"
        android:text="I'm on the left in the middle"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/center_button"
        android:layout_centerHorizontal="true"
        android:text="I'm at the top of the middle"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/center_button"
        android:text="I'm right in the middle"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/center_button"
        android:layout_centerHorizontal="true"
        android:text="I'm at the bottom of the middle"/>

</RelativeLayout>

Video download address

Video download address:

Links: https://pan.baidu.com/s/1o8G7hCe Password: 7qnt

Welcome to the WeChat Public Number

Tags: Android xml encoding

Posted on Thu, 25 Jun 2020 12:33:12 -0400 by pillot1005