Android, layout Summary (Common layout rules)

Source: Internet
Author: User

1. When using Relativelayout, set the properties to Relativelayout:
Android:gravity= "Center_vertical", the top height of the container's sub-view is vertically centered,
Other relatively short sub-view is on top of the highest child view layout.
2. In the Relativelayout, if, Relativelayout used the android:gravity,
For example: android:gravity: "Center:vertical", then the child view using Android:layout_alignparentbottom
Causes the Gravity property of the parent view to be invalidated and affects other child view.

Summary when using the Relativelayout layout, if there are multiple sub-view, you need all the word view Horizontal vertical Center
Then there are two ways:
1. Parent view does not add android:gravity= "center-vertical", each child view adds an android:
Layout_centervetical= the "true" property.

As follows:

<?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=" 250DP "
Android:background = "#000";
<textview
android:id= "@+id/mydd"
android:layout_width= "50DP"
android:layout_height= "90DP"
android:background= "#666"
android:layout_alignparentright= "true"
Android:layout_centervertical = "true"
android:text= "haha"
/>
<textview
android:id= "@+id/dd2"
android:layout_width= "60DP"
android:layout_height= "60DP"
android:background= "#888"
Android:layout_centervertical= "true"

android:layout_toleftof= "@id/mydd"
android:text= "haha"
/>
<imageview
android:layout_width= " 50DP "
android:layout_height=" 40DP "
Android:layout_centervertical=" true "
android:layout_toleftof=" @id/ DD2 "
android:src=" @android:d rawable/btn_default "
/>
</relativelayout>


2. Parent View plus android:gravity= "center-vertical", each child view plus android:gravity
= "Center-vertical" and then centered according to Android:alignbaseline. (Suitable for sub-view can set gravity
's view)

The code is as follows:

<?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= "250DP"
Android:background= "#000"
android:gravity= "Center_vertical" >
<textview
Android:id= "@+id/mydd1"
Android:layout_width= "50DP"
android:layout_height= "90DP"
Android:background= "#666"
Android:gravity= "Center_vertical"
Android:layout_alignparentright= "true"
android:text= "haha"
/>
<textview
Android:id= "@+id/ddd"
Android:layout_width= "60DP"
android:layout_height= "60DP"
Android:background= "#888"
Android:gravity= "Center_vertical"
android:layout_toleftof= "@id/mydd1"
android:text= "haha"
Android:layout_alignbaseline= "@id/mydd1" ></TextView></RelativeLayout>

Android, layout Summary (Common layout rules)

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.