1. Linear layout
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Horizontal" <!--horizontal for horizontal arrangement vertical vertical arrangement--Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Button1" /> <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Button2" /> <ButtonAndroid:id= "@+id/button3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Button3" /></LinearLayout>
Select alignment by Layout_gravity
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Horizontal"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Top"Android:text= "Button1" /> <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center_vertical"Android:text= "Button2" /> <ButtonAndroid:id= "@+id/button3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Bottom"Android:text= "Button3" /></LinearLayout>
As shown
Layout_width to set the scale of the screen the system adds all the controls under LinearLayout to the total value and then the layout_width of each control is the scale.
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Horizontal"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <EditTextAndroid:id= "@+id/input_message"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "3"Android:hint= "Type Something" /> <ButtonAndroid:id= "@+id/send"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "2"Android:text= "Send" /></LinearLayout>
As shown
If the button's layout_width is set to Wrap_content, EditText's layout_weight is set to 1 for the following display
2. Relative layout
Four basic layouts of android--