Learn relative layout of android & lt; RelativeLayout from scratch. 16. & gt;, android get layout

Source: Internet
Author: User

Learn relative layout of android <RelativeLayout. 16.> from scratch. android gets layout.
The relative layout manager refers to the placement of a widget by referring to other Widgets. You can control the placement of components in the upper, lower, left, and right positions of a specified reference component, these can be done directly through the properties provided by each component. The following describes the basic usage of each method.

No. Attribute name Corresponding rule constant Description
1 Android: layout_below RelativeLayout. BELOW Placed under the specified component
2 Android: layout_toLeftOf RelativeLayout. LEFT_OF Placed on the left of the specified component
3 Android: layout_toRightOf RelativeLayout. RIGHT_OF Placed on the right of the specified component
4 Android: layout_alignTop RelativeLayout. ALIGN_TOP Align with specified components for Reference
5 Android: layout_alignBottom RelativeLayout. ALIGN_BOTTOM Align with specified components for Reference
6 Android: layout_alignLeft RelativeLayout. ALIGN_LEFT Align left with specified components for Reference
7 Android: layout_alignRight RelativeLayout. ALIGN_RIGHT Align right with specified components for Reference

<Span style = "font-size: 18px;"> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: paddingBottom = "@ dimen/activity_vertical_margin" android: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/android" android: PaddingTop = "@ dimen/activity_vertical_margin" android: textAlignment = "center" tools: context = ". mainActivity "> <EditText android: id =" @ + id/editText1 "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: layout_alignParentRight =" true "android: layout_alignParentTop = "true" android: EMS = "10"/> <EditText android: id = "@ + id/editText2" android: layout_width = "wrap_content" android: la Yout_height = "wrap_content" android: layout_alignRight = "@ + id/editText1" android: layout_below = "@ + id/editText1" android: EMS = "10" android: inputType = "textPassword"> <requestFocus/> </EditText> <TextView android: id = "@ + id/textView1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignBottom = "@ + id/editText1" android: layout_alignParentLeft = "true" android: text = "Account" /> <TextView android: id = "@ + id/textView2" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignBottom = "@ + id/editText2" android: layout_alignParentLeft = "true" android: text = "password" android: textAlignment = "center"/> <Button android: id = "@ + id/button1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ + id/editText2" android: Layout_marginLeft = "23dp" android: layout_marginTop = "36dp" android: layout_toRightOf = "@ + id/textView2" android: text = "login"/> <TextView android: id = "@ + id/textView3" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignBottom = "@ + id/button1" android: layout_marginLeft = "14dp" android: layout_toRightOf = "@ + id/button1" android: autoLink = "web" android: linksClickable = "true" Android: text = "forgot password" android: textAppearance = "? Android: attr/textAppearanceSmall "android: textSize =" 10dp "/> </RelativeLayout> </span>

Relative layout is currently the main layout method. It is more convenient and convenient than other methods. You can drag it directly on the visual interface.
.................................................................. Beautiful cut line ..................................................................
The use of dynamic table layout is the same as the previous one. It is not often used here and will not be repeated here. Interested readers can try it on their own. You need to use the following methods.
1 Public RelativeLayout. LayoutParams (int w, int h) Structure Specify the width and height of the RelativeLayout Layout
2 Public void addRule (int verb, int anchor) Normal Add specified parameter rules
3 Public int [] getRules () Normal Obtains all the parameter rules of a component.



Next prediction: Use nested layout to implement the calculator Interface


RelativeLayout

<

RelativeLayout xmlns: android = "schemas.android.com/apk/res/android"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

Android: background = "# fd8d8d"

Android: gravity = "center">

<Button

Android: id = "@ + id/button"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: layout_centerVertical = "true"

Android: text = "BUTTON"

Android: textSize = "16sp"/>

<Button

Android: id = "@ + id/button2"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: layout_below = "@ id/button"

Android: layout_toRightOf = "@ id/button"

Android: text = "BUTTON2"

Android: textSize = "16sp"/>

<Button

Android: id = "@ + id/button1"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: layout_above = "@ id/button"

Android: layout_toRightOf = "@ id/button"

Android: text = "BUTTON1"

Android: textSize = "16sp"/>

</

RelativeLayout>... the remaining full text>

Relativelayout layout in Android Development

You can see what layout you are using. If it is LinearLayout, the following controls are arranged with the distance between you. If it is RelativeLayout, You need to specify the method. There are many methods, such as android: layout_below and android: layout_abve, layout_alignParentRight, layout_toRightOf, or layout_toLeftOf

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.