Relative layout of RelativeLayout from the ground up

Source: Internet
Author: User

 

Relatively layout is not familiar with Web development. We often use these similar relative la s when using CSS + DIV. When setting the position of a DIV, we often use a DIV as a reference to set the position. If you don't talk about it, you can directly look at the attribute to view the instance.

 

Attribute name

Description

Android: layout_below

Placed under the specified component

Android: layout_toLeftOf

Placed on the left of the specified component

Android: layout_toRightOf

Placed on the right of the specified component

Android: layout_alignTop

Alignment with specified components as reference

Android: layout_algnBottom

Bottom alignment with specified component as reference

Android: layout_alignLeft

Align left with specified components as reference

Android: layout_alignRight

To specify Components

 

The preceding example shows how to implement relative layout.

 

<? Xml version = "1.0" encoding = "UTF-8"?>

 

<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"

 

Android: orientation = "vertical" android: layout_width = "fill_parent"

 

Android: layout_height = "wrap_content">

 

 

<EditText android: layout_width = "wrap_content"

 

Android: layout_height = "wrap_content" android: layout_alignParentTop = "true"

 

Android: layout_alignParentRight = "true" android: layout_toRightOf = "@ + id/TV _username"

 

Android: id = "@ + id/txt_username">

 

</EditText>

 

<EditText android: layout_width = "wrap_content"

 

Android: layout_height = "wrap_content" android: layout_below = "@ + id/txt_username"

 

Android: layout_alignLeft = "@ + id/txt_username"

 

Android: layout_alignParentRight = "true" android: id = "@ + id/txt_password"> </EditText>

 

<TextView android: id = "@ + id/TV _username" android: layout_width = "wrap_content"

 

Android: layout_height = "wrap_content" android: text = "User Name"

 

Android: layout_alignParentTop = "true" android: layout_alignParentLeft = "true"

 

Android: layout_marginTop = "14dp"> </TextView>

 

<Button android: text = "login" android: layout_width = "wrap_content"

 

Android: layout_height = "wrap_content" android: layout_below = "@ + id/txt_password"

 

Android: layout_alignParentRight = "true" android: layout_alignLeft = "@ + id/txt_password"

 

Android: id = "@ + id/btn_login"> </Button>

 

<Button android: text = "cancel" android: layout_width = "wrap_content"

 

Android: layout_height = "wrap_content" android: layout_below = "@ + id/txt_password"

 

Android: layout_alignRight = "@ + id/TV _username" android: id = "@ + id/btn_cacel"> </Button>

 

<TextView android: id = "@ + id/TV _password" android: layout_width = "wrap_content"

 

Android: layout_height = "wrap_content" android: text = "User Password"

 

Android: layout_centerVertical = "true" android: layout_toLeftOf = "@ + id/txt_password"> </TextView>

 

 

</RelativeLayout>

 

 

Instance effect:

 


From jiahui524 Column

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.