Android relative layout achieves various plum blossom Effects

Source: Internet
Author: User

 

 

1. as follows:

 

The first part is to put an image named icon.png in the drawablefolder. First, it indicates that Android only supports images with the extension png, jpg, and gif;

 

Then write the main. xml file with the following code:

 

 

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

<ImageButton

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/icon"

Android: layout_centerInParent = "true"

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

<ImageButton

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/icon"

Android: layout_above = "@ id/image0"

Android: layout_toLeftOf = "@ id/image0"

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

<ImageButton

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/icon"

Android: layout_above = "@ id/image0"

Android: layout_toRightOf = "@ id/image0"

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

<ImageButton

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/icon"

Android: layout_below = "@ id/image0"

Android: layout_toLeftOf = "@ id/image0"

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

<ImageButton

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/icon"

Android: layout_below = "@ id/image0"

Android: layout_toRightOf = "@ id/image0"

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

</RelativeLayout>

Note:

 

Android: layout_above: Move the control's bottom to the control with the given Id

 

Android: layout_below: place the top 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: alignbaseline

 

Android: layout_alignBottom: Align the bottom edge of the control with the bottom edge of the given ID Control

 

Android: layout_alignLeft: Align the left edge of the control with the given ID

 

Android: layout_alignRight: Align the right edge of the control with the right edge of the given ID Control

 

Android: layout_alignTop: Align the top edge of the control with the top edge of the given ID Control

 

 

 

Android: alignParentBottom if the value is true, the bottom of the control is aligned with the bottom of the parent control.

 

Android: layout_alignParentLeft if the value is true, the left side of the control is aligned with the left side of the parent control.

 

Android: layout_alignParentRight: If this parameter is set to true, the right side of the control is aligned with the right side of the parent control.

 

Android: layout_alignParentTop if the value is true, the top of the control is aligned with the top of the parent control.

 

 

 

Android: layout_centerHorizontal

 

Android: layout_inParent if the value is true, the control is centered in the horizontal and vertical directions of the parent control.

 

Android: layout_centerVertical if the value is true, the control will be centered in the vertical direction

 

Ii. Results

 

First, put an image named leaf.png in the drawablefolder.

 

Compile the main. xml file with the following code:

 

 

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

>

<! -- Define that the component is located in the middle of the parent container -->

<TextView

Android: id = "@ + id/view01"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/leaf"

Android: layout_centerInParent = "true"

/>

<! -- Define that the component is located above the view01 component -->

<TextView

Android: id = "@ + id/view02"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/leaf"

Android: layout_above = "@ id/view01"

Android: layout_alignLeft = "@ id/view01"

/>

<! -- Define that the component is located below the view01 component -->

<TextView

Android: id = "@ + id/view03"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/leaf"

Android: layout_below = "@ id/view01"

Android: layout_alignLeft = "@ id/view01"

/>

<! -- Define that the widget is on the left of the view01 widget -->

<TextView

Android: id = "@ + id/view04"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/leaf"

Android: layout_toLeftOf = "@ id/view01"

Android: layout_alignTop = "@ id/view01"

/>

<! -- Define that the widget is on the right of the view01 widget -->

<TextView

Android: id = "@ + id/view05"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: background = "@ drawable/leaf"

Android: layout_toRightOf = "@ id/view01"

Android: layout_alignTop = "@ id/view01"

/>

</RelativeLayout>

 

Description: To control the distribution of child components in the layout container, RelativeLayout provides an internal class: RelativeLayout. layoutParams, which provides a large number of xml attributes to control the layout distribution of the RelativeLayout layout container neutron components;

 

 

 

In addition, RelativeLayout. layoutParams also inherits android. view. viewGroup. marginLayoutParams, so every child component in the RelativeLayout layout container can also specify android. view. viewGroup. the xml attributes supported by MarginLayoutParams.

 

 

Author Ren haili

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.