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)