Relativelayout of Android layout (relative layout)

Source: Internet
Author: User

The relative layout has many attributes, so it is a little effort to use it, but it is more flexible than other layout methods, so it is very useful to master the relative layout. Let's take a look at an example:

1 <? XML version = "1.0" encoding = "UTF-8"?>
2 <relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
3 Android: layout_width = "fill_parent"
4 Android: layout_height = "fill_parent">
5 <textview
6 Android: Id = "@ + ID/label"
7 Android: layout_width = "fill_parent"
8 Android: layout_height = "wrap_content"
9 Android: text = "type here:"/>
10 <edittext
11 Android: Id = "@ + ID/entry"
12 Android: layout_width = "fill_parent"
13 Android: layout_height = "wrap_content"
14 Android: Background = "@ Android: drawable/editbox_background"
15 Android: layout_below = "@ ID/label"/>
16 <button
17 Android: Id = "@ + ID/OK"
18 Android: layout_width = "wrap_content"
19 Android: layout_height = "wrap_content"
20 Android: layout_below = "@ ID/entry"
21 Android: layout_alignparentright = "true"
22 Android: layout_marginleft = "10dip"
23 Android: text = "OK"/>
24 <button
25 Android: layout_width = "wrap_content"
26 Android: layout_height = "wrap_content"
27 Android: layout_toleftof = "@ ID/OK"
28 Android: layout_aligntop = "@ ID/OK"
29 Android: text = "cancel"/>
30 </relativelayout> This is a common layout. The following describes the layout content: 1 Android: layout_below = "@ ID/label"/>

Place the current control under the control whose ID is label.

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

1 Android: layout_marginleft = "10dip"

Empty space on the left of the current control.

1 Android: layout_toleftof = "@ ID/OK"

Place the current control on the left of the control whose ID is OK.

1 Android: layout_aligntop = "@ ID/OK"

Align the upper end of the current control with the ID control.

So far, we have found that there are many attributes. Below is a brief summary:
Class 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
Class 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
Category 3: attribute values are specific pixel values, such as 30dip and 40px.
* Android: layout_marginbottom
* Android: layout_marginleft
* Android: layout_marginright
* Android: layout_margintop

Let's look at the second example:

1 <? XML version = "1.0" encoding = "UTF-8"?>
2 <relativelayout
3 xmlns: Android = "http://schemas.android.com/apk/res/android"
4 Android: layout_width = "fill_parent"
5 Android: layout_height = "fill_parent">
6
7 <analogclock
8 Android: Id = "@ + ID/aclock"
9 Android: layout_width = "wrap_content"
10 Android: layout_height = "wrap_content"
11 Android: layout_centerinparent = "true"/>
12 <digitalclock
13 Android: Id = "@ + ID/dclock"
14 Android: layout_width = "wrap_content"
15 Android: layout_height = "wrap_content"
16 Android: layout_below = "@ ID/aclock"
17 Android: layout_alignleft = "@ ID/aclock"
18 Android: layout_marginleft = "40px"/>
19 <textview
20 Android: layout_width = "wrap_content"
21 Android: layout_height = "wrap_content"
22 Android: text = "current time :"
23 Android: layout_toleftof = "@ ID/dclock"
24 Android: layout_aligntop = "@ ID/aclock"/>
25 </relativelayout>

Two examples are as follows: the first example

Example 2

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.