Android study note 8: relativelayout

Source: Internet
Author: User

 

Relativelayout is relative layout. The components in this layout are always determined by relative sibling components and parent containers. when defining the widget location, you need to refer to the location of other controls.

This program implements a relative layout of plum blossom

<? 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 the left alignment of the widget above view01 and view01 --> <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 at the bottom of 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 the component to the left of the view01 component --> <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 the component to the right of the view01 component --> <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>

Dynamically set the widget spacing in the activity

Import android. app. activity; import android. OS. bundle; public class relativelayouttest extends activity {@ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); findviewbyid (R. id. view01 ). setpadding (5, 5, 5, 5); // you can specify the findviewbyid (R. id. view02 ). setpadding (5, 5, 5, 5); findviewbyid (R. id. view03 ). setpadding (5, 5, 5, 5); findviewbyid (R. id. view04 ). setpadding (5, 5, 5, 5); findviewbyid (R. id. view05 ). setpadding (5, 5, 5, 5 );}}


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.