LinearLayout
1. Core attributes
Height: layout_height (based on content wrap_content; parent control;)
Width: layout_width
Direction: orientation (longitudinal vertical; transverse horizontal;)
Location: layout_gravity (center center; right;)
2. Equal control
Layout_width set to 0DP layout_weight to weight ratio is recommended by Google
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Match_parent"> <!--horizontal layout_width= "Match_parent" determines its width based on the width of the parent control - <LinearLayoutandroid:orientation= "Horizontal"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Match_parent"> <!--Layout_width set to 0DP layout_weight to weight ratio is recommended by Google - <ButtonAndroid:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:background= "#234578"Android:text= "equal to 1"/> <ButtonAndroid:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:background= "#234578"Android:text= "equal to 1"/> <ButtonAndroid:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "2"Android:background= "#284578"Android:text= "equal (+)"/> </LinearLayout> <!--Horizontal non-uniform layout_width= "wrap_content" determines its width depending on the width of the content - <LinearLayoutandroid:orientation= "Horizontal"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"Android:layout_margintop= "10DP"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#897654"Android:text= "Non-equal 1"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#897654"Android:text= "===== non-uniform 123====="/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:textallcaps= "false"Android:background= "#897654"Android:text= "Demo"/> </LinearLayout> <!--Horizontal Dividing - <LinearLayoutandroid:orientation= "Horizontal"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Match_parent"Android:layout_width= "Wrap_content"Android:layout_margintop= "10DP"> <!--Vertical Dividing - <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Match_parent"Android:layout_width= "0DP"Android:layout_weight= "1"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "0DP"Android:layout_weight= "2"Android:background= "#457421"Android:text= "equal to 1"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "0DP"Android:layout_weight= "1"Android:background= "#126735"Android:text= "equal to 2"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "0DP"Android:layout_weight= "1"Android:background= "#843975"Android:text= "equal to 3"/> </LinearLayout> <!--vertical row values determine height - <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "0DP"Android:layout_weight= "1"Android:layout_marginleft= "20DP"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"Android:background= "#547836"Android:text= "Button 1"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "66DP"Android:background= "#837282"Android:text= "button 2"/> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "98DP"Android:layout_weight= "2"Android:background= "#973422"Android:text= "button 3"/> </LinearLayout> </LinearLayout> <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"android:layout_gravity= "Right"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"Android:background= "#547836"Android:text= "On the right"/> </LinearLayout> <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"android:layout_gravity= "Center"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"Android:background= "#547836"Android:text= "Centered"/> </LinearLayout></LinearLayout>
Android Layout LinearLayout