Introduction to Android relativelayout (relative layout)

Source: Internet
Author: User

 

 

Example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Type here:"/>
    <EditText
        android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_below="@id/label"/>
    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/entry"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text="OK" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/ok"
        android:layout_alignTop="@id/ok"
        android:text="Cancel" />
</RelativeLayout>

First:

        android:layout_below="@id/label"/>

It indicates that the current control is placed under the control whose ID is label.

        android:layout_alignParentRight="true"

Align the right end of the current control with the right end of the parent control. The attribute value can only be true or false. The default value is false.

android:layout_marginLeft="10dip"

To make the left side of the current control empty.

        android:layout_toLeftOf="@id/ok"

Indicates that the current control is placed on the left side of the control whose ID is OK.

        android:layout_alignTop="@id/ok"

Indicates alignment between the current control and the upper end of the ID control.

The relative layout mainly has the following attributes:

Attribute 1: the property value is true or false.
* Android: layout_centerhrizontal
* Android: layout_centervertical
* Android: layout_centerinparent
* Android: layout_alignparentbottom
* Android: layout_alignparentleft
* Android: layout_alignparentright
* Android: layout_alignparenttop
* Android: layout_alignwithparentifmissing
Attribute 2: the property value must be the reference name "@ ID/ID-name" of the ID"
* Android: layout_below
* Android: layout_abve
* Android: layout_toleftof
* Android: layout_torightof
* Android: layout_aligntop
Attribute 3: The attribute value is a specific pixel value, measured in dip and PX.
* Android: layout_marginbottom
* Android: layout_marginleft
* Android: layout_marginright
* Android: layout_margintop

XML example:

<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">

<Analogclock
Android: Id = "@ + ID/aclock"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_centerinparent = "true"/>
<Digitalclock
Android: Id = "@ + ID/dclock"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_below = "@ ID/aclock"
Android: layout_alignleft = "@ ID/aclock"
Android: layout_marginleft = "40px"/>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "current time :"
Android: layout_toleftof = "@ ID/dclock"
Android: layout_aligntop = "@ ID/aclock"/>
</Relativelayout>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.