Android---4---layout of relativelayout

Source: Internet
Author: User

Relativelayout, also known as relative layout, is a very common layout.

Unlike the linearlayout arrangement rules, it is more casual, and it can be used in a relatively positioned way to make the control appear anywhere in the layout.

By relative layout we can implement something like this:



android:layout_centerhorizontal="True" allows the control to be centered horizontally by this property

Android:layout_alignparentbottom="true" this property allows the control to be at the bottom

android:layout_centervertical="true" this property causes the control to be centered vertically

android:layout_alignparentright="true" this property causes the control to be on the right side of the parent layout

android:layout_centerinparent="true" this property causes the control to be in the center of the parent layout

android:layout_toleftof="@id/button" This property causes the control to be located to the left of the control with the ID button

android:layout_torightof="@id/button" the same, the control is on the right side of the button

android:layout_above="@id/button" is above the button

Android:layout_below="@id/button" is located below the button



The following code allows you to implement this interface using the above method.


<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" Match_parent "> <button android:        Layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centerhorizontal= "true" android:text= "Attack"/> <button android:layout_width= "wrap_content" android:layout_height= "Wrap_con" Tent "android:layout_alignparentbottom=" true "android:layout_centerhorizontal=" true "android:text=" escape "/> <button android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Androi        D:layout_centervertical= "true" android:text= "left hook fist"/> <button android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentright= "true" android:layout_centervertic Al= "true" android:text= "right hook"Fist "/> <button android:id=" @+id/button "android:layout_width=" Wrap_content "android:layout_he ight= "Wrap_content" android:layout_centerinparent= "true" android:text= "must Kill"/> <button Androi        D:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centervertical= "true" android:layout_toleftof= "@id/button" android:text= "left"/> <button android:layout_width= "Wrap_cont Ent "android:layout_height=" Wrap_content "android:layout_centervertical=" true "android:layout_toright of= "@id/button" android:text= "right"/> <button android:layout_width= "Wrap_content" Android:layo ut_height= "Wrap_content" android:layout_above= "@id/button" android:layout_centerhorizontal= "true" and        roid:text= "on"/> <button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_below= "@id/button" android:layout_centerhorizontal= "true" android:text= "under"/></relativelayout> 


Android---4---layout of relativelayout

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.