"Android" chapter 7th (6) relativelayout (relative layout)

Source: Internet
Author: User

Category: C #, Android, VS2015;

Date Created: 2016-02-11

First, Introduction

Relativelayout is a relative layout in which the position of a child element of a container is calculated relative to the position of its previous element or other element, or is calculated relative to the filled area of its parent container.

1. When to use relative layout

Typically, relative layouts are used in nested sub-regions, which can provide significant performance, especially for multi-layered nesting, much higher than with linearlayout performance.

Remember: The sole purpose of using relative layouts is to keep the relative positions between child elements intact.

2. Common Properties

Target component: Specified with ID.

Unit of measure: can be either a pixel (for example, 30dip, 40px) or a pixel-independent unit (DP).

Android:layout_above above the target component

Aligns the android:layout_alignbaseline with the baseline of the target component.

Android:layout_alignbottom the bottom edge of the lower edge and the target component

Android:layout_alignend End and target component end alignment

Android:layout_alignright the right edge of the right edge and the target component

Android:layout_alignleft left edge and target component left edge aligned

Android:layout_alignstart start and target component start-up alignment

Android:layout_aligntop the top of the top and the target component are aligned

Android:layout_below below the target component

Android:layout_toendof at the end of the target component

Android:layout_toleftof on the left side of the target component

Android:layout_torightof on the right side of the target component

Android:layout_alignleft at the starting end of the target component

3. Alignment with the target component

Defined by Relavielayout.layoutparams (TRUE or false).

Android:layout_alignparentbottom is aligned with the bottom of the parent element.

Whether the android:layout_alignparentend is aligned with the end of the parent element.

Android:layout_alignparentleft is aligned to the left of the parent element

Android:layout_alignparentright is aligned to the right of the parent element

Whether the Android:layout_alignparentstart is aligned with the start of the parent element

Android:layout_alignparenttop is aligned with the top of the parent element

Android:layout_alignwithparentifmissing the target element is not found as a reference to the parent element

Second, example--demo04relativelayout

1. Operation

2. Add Demo04relativelayout.axml File

Add the file under the Resources/layout folder.

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">    <RelativelayoutAndroid:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">        <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Please enter content:" />        <EditTextAndroid:id= "@+id/edittext1"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:background= "@android:d rawable/editbox_background"Android:layout_below= "@id/textview1" />        <ButtonAndroid:id= "@+id/ok"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@id/edittext1"Android:layout_alignparentright= "true"Android:layout_marginleft= "10dip"Android:text= "OK" />        <ButtonAndroid:id= "@+id/cancel"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_toleftof= "@id/ok"Android:layout_aligntop= "@id/ok"Android:text= "Cancel" />    </Relativelayout></LinearLayout>

3. Add Demo04RelativeLayout.cs File

Add the file under the Srcdemos folder.

usingAndroid.app;usingAndroid.os;usingAndroid.widget;namespaceCh07demos. srcdemos{[Activity (Label="Demo04relativelayout")]     Public classdemo04relativelayout:activity {protected Override voidOnCreate (Bundle savedinstancestate) {Base.            OnCreate (savedinstancestate);            Setcontentview (Resource.Layout.Demo04RelativeLayout); Findviewbyid<Button> (Resource.Id.ok). Click + =Delegate{Toast.maketext ( This,"you clicked [OK]", Toastlength.long).            Show ();            }; Findviewbyid<Button> (Resource.Id.cancel). Click + =Delegate{Toast.maketext ( This,"you clicked [Cancel]", Toastlength.long).            Show ();        }; }    }}

"Android" chapter 7th (6) relativelayout (relative layout)

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.