Android ApiDemos example resolution (151): Views-& gt; Layouts-& gt; Rela

Source: Internet
Author: User

RelativeLayout allows child elements to specify their locations (by ID) relative to other elements or parent layout objects.

In this example, RelativeLayout is used to display three textviews. The second TextView (id/view3) occupies the middle part of the screen. We have discussed how to use LinearLayout, use the specified View weight to achieve the same effect. Android ApiDemos example resolution (143): Views-> Layouts-> LinearLayout-> 3. vertical (Padded)

In this example, RelativeLayout is used. Because other views need to be used as reference objects, all child views must define IDs. Other child views determine their relative positions by specifying the IDs of the reference objects.

<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">

<! -View1 goes on top->
<TextView
Android: id = "@ + id/view1 ″
Android: background = "@ drawable/red"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_alignParentTop = "true"
Android: text = "@ string/relative_layout_{top"/>

<! -View2 goes on the bottom->
<TextView
Android: id = "@ + id/view2 ″
Android: background = "@ drawable/green"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_alignParentBottom = "true"
Android: text = "@ string/relative_layout_1_bottom"/>

<! -View3 stretches betweeen view1 and view2->
<TextView
Android: id = "@ + id/view3 ″
Android: background = "@ drawable/yellow"
Android: layout_width = "match_parent"
Android: layout_height = "0dip"
Android: layout_above = "@ id/view2 ″
Android: layout_below = "@ id/view1 ″
Android: text = "@ string/relative_layout_centercenter"/>

</RelativeLayout>

TextView1 (id/view1) indicates that its layout_alignParentTop relative to the parent container RelativeLayout is True, so it is displayed on the top of the screen.

TextView2 (id/view2) indicates that its android: layout_alignParentBottom relative to RelativeLayout of the parent container is True, so it is displayed at the bottom of the screen.

TextView3 (id/view3) is set to 0, but android: layout_above and android: layout_below indicate the relative position between TextView1 and TextView2 (adjacent to the top and bottom of two textviews ), therefore, TextView3 occupies all the remaining intermediate parts.

 

 


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.