LinearLayout Properties & Attributes Guide
Commonly used attributes in LinearLayout layout include:
- Set the layout direction using android:orientation, choose between horizontal (for a horizontal layout) or vertical (for a vertical layout).
- android:layout_width: This attribute is used to define the width of a layout and can be set to a specific value (such as 100dp) or match_parent (to fill the parent container).
- android:layout_height: Sets the height of the layout, can be set to a specific value (ex. 100dp) or match_parent.
- android:layout_weight: It allows you to set the weight of a layout, which controls how the layout is allocated within its parent container.
- android:gravity: Specifies the alignment of child elements within the layout, with options including top, bottom, left, right, and center.
- android:padding: sets the inner padding of the layout to control the spacing between the child elements and the parent container.
- android:paddingTop, android:paddingBottom, android:paddingLeft, android:paddingRight: adjust the top, bottom, left, and right margins of the layout, respectively.
- android:layout_margin: Used to set the outer margin of the layout, controlling the spacing between the layout and other views.
- Set the top, bottom, left, and right margin of the layout using android:layout_marginTop、android:layout_marginBottom、android:layout_marginLeft、android:layout_marginRight attributes respectively.