Android relativelayout attributes and usage to achieve the effect that the view above is superimposed on the view below

Source: Internet
Author: User
Android relativelayout attributes

// Relative to the given ID Control

Android: layout_above: place the bottom of the control on the control with the given ID;

Android: layout_below: place the bottom of the control under the control with the given ID;

Android: layout_toleftof align the right edge of the control with the left edge of the control with the given ID;

Android: layout_torightof align the left edge of the control with the right edge of the control with the given ID;

Android: layout_alignbaseline: Align the baseline of the control with the baseline of the given ID;

Android: layout_aligntop: Align the top edge of the control with the top edge of the given ID;

Android: layout_alignbottom: Align the bottom edge of the control with the bottom edge of the given ID;

Android: layout_alignleft: Align the left edge of the control with the left edge of the given ID;

Android: layout_alignright: Align the right edge of the control with the right edge of the given ID;

// Relative to the parent component

Android: layout_alignparenttop if it is true, align the top of the control with the top of its parent control;

Android: layout_alignparentbottom: If this parameter is set to true, the bottom of the control is aligned with the bottom of its parent control;

Android: layout_alignparentleft: if it is true, align the left of the control with the left of its parent control;

Android: layout_alignparentright: if it is set to true, align the right of the control with the right of its parent control;

// Center

Android: layout_centerhorizontal if true, place the control horizontally in the center;

Android: layout_centervertical if true, place the control vertically in the center;

Android: layout_centerinparent if true, place the control in the center of the parent control;

// Specify the moving Pixel

Android: layout_margintop offset value;

Android: layout_marginbottom offset value;

Android: layout_marginleft value of the left offset;

Android: value of the right offset of layout_marginright;

 

Example:

1.

 

Android: layout_below = "@ ID /***"

Android: layout_alignbaseline = "@ ID /***"

Android: layout_alignparenttop = true

Android: layout_marginleft = "10px"

2. Use relativelayout to overwrite the following view.

For any layout, you can set the property of Android: layout_marginxxx to a negative value to overlay adjacent views,

For example:

Android: layout_margintop = "-50dip" can overlay the 50dip area with the adjacent top view.

However, the order of their descriptions in the XML file determines who overlays them, and what appears later.
Therefore, you cannot use linearlayout to overwrite the view on the layout. For linearlayout, when describing a view in an XML file, you must first describe the view above and then describe the view below. Therefore, the view below will overwrite the view above.
You can use relativelayout. Because in the relativelayout layout, We can first describe the view at the bottom, and then describe the view above. (Note that the view described first needs to use the view ID described later. You need to use "@ + ID/Corresponding viewid ")
For example, the blue button will overwrite the green button.

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

Android: Orientation = "vertical"

>

<Button Android: layout_below = "@ + ID/Bt1"

Android: layout_above = "@ + ID/bt2"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

Android: Background = "# ff00ff00"

Android: layout_margintop = "-50dip"

/>

<Button Android: Id = "@ + ID/Bt1"

Android: layout_width = "fill_parent"

Android: layout_height = "100dip"

Android: Background = "# ff0000ff"

/>

<Button Android: Id = "@ + ID/bt2"

Android: layout_alignparentbottom = "true"

Android: layout_width = "fill_parent"

Android: layout_height = "100dip"

Android: Background = "# ff0000ff"

/>

</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.