The relativelayout of Android common layout controls

Source: Internet
Author: User
Tags relative

We use LinearLayout and tablelayout to meet the basic requirements for developing the application interface. But sometimes when the interface is not flexible enough, we can also use another kind of control relativelayout. Relativelayout is a relative layout of the control, the container inside the child elements can use each other relative position or and the relative position between the container positioning, similar to the web design CSS. When you specify the position of the control, we need to specify a relative position between the control and the other controls, such as the left alignment of another control, the right alignment, the top of the other control, and so on. A control can specify the relative position of multiple other controls. In this way, we will be more convenient in the design of the flexible location of the interface.

Android Relativelayout Properties

Relative to the given ID control
Android:layout_above Place the bottom of the control over the control with the given ID;
Android:layout_below Place the bottom of the control under the control of the given ID;
Android:layout_toleftof aligns the right edge of the control with the left edge of the control with the given ID;
Android:layout_torightof aligns the left edge of the control with the right edge of the control with the given ID;
Android:layout_alignbaseline aligns the baseline of the control with the baseline of the given ID;
Android:layout_aligntop aligns the top edge of the control with the top edge of the given ID;
Android:layout_alignbottom aligns the bottom edge of the control with the bottom edge of the given ID;
Android:layout_alignleft aligns the left edge of the control with the left edge of the given ID;
Android:layout_alignright aligns the right edge of the control with the right edge of the given ID;
Relative to Parent component
Android:layout_alignparenttop If true, aligns the top of the control with the top of its parent control;
Android:layout_alignparentbottom If true, aligns the bottom of the control with the bottom of its parent control;
Android:layout_alignparentleft If true, aligns the left part of the control with the left part of its parent control;
Android:layout_alignparentright If true, aligns the right part of the control with the right part of its parent control;
Center
Android:layout_centerhorizontal If True, centers the control horizontally;
Android:layout_centervertical If True, centers the control vertically;
Android:layout_centerinparent If true, place the control in the center of the parent control;
Specifies that the pixel is moved, and the value is px
The value of the offset on the android:layout_margintop;
Android:layout_marginbottom the value of the offset;
The value of the android:layout_marginleft left offset;
Android:layout_marginright the value of the right offset;

Example:

01.<?xml version= "1.0" encoding= "Utf-8"?> 02.<relativelayout xmlns:android= "http://schemas.android.com/"    Apk/res/android "03.    Android:layout_width= "Fill_parent" 04.    android:layout_height= "Fill_parent" 05.    android:padding= "10px" 06.    > 07.    <textview 08.    Android:id= "@+id/textview" 09.    android:text= "TextView" 10.    Android:layout_width= "Fill_parent" 11.    android:layout_height= "Wrap_content" 12.    /> 13.    <!--did not set the location of the TextView, the default is the Relativelayout container in the upper left corner--> 14.    <edittext 15.    Android:id= "@+id/edittext" 16.    Android:layout_width= "Fill_parent" 17.    Android:layout_height= "Wrap_content" 18.    android:layout_below= "@id/textview" 19.    android:background= "@android:d rawable/editbox_background" 20.    /> 21.    <!--EditText Control is located under the TextView control--> 22.    <button 23.    Android:id= "@+id/buttonsure" 24.    Android:text= "OK" 25.    Android:layout_width= "Wrap_content" 26.    Android:layout_height= "Wrap_content" 27. Android:layout_below= "@id/edittext" 28.    Android:layout_alignparentright= "true" 29.    android:layout_marginleft= "10px" 30.    /> 31.  <!--the Buttonsure control is below the EditText control, and the location of the parent container is right-aligned.                    Android:layout_marginleft= "10px" 32.    Sets the left margin of the buttonsure control to 10 pixels, that is, the distance from the left of this control is 10 pixels from the other control--> 33.    <button 34.    Android:id= "@+id/buttoncancel" 35.    Android:text= "Cancel" 36.    Android:layout_width= "Wrap_content" 37.    Android:layout_height= "Wrap_content" 38.    android:layout_toleftof= "@id/buttonsure" 39.    android:layout_aligntop= "@id/buttonsure" 40.    /> 41. <!--Buttoncancel is determined relative to the buttonsure position.                    The right edge of the Buttoncancel control is aligned with the left edge of the Buttonsure control, 42. The top edge is aligned with the top edge of the Buttonsure control--> 43.</relativelayout>

Related Article

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.