What is Linear Layout in Android?
Linear Layout is a simple layout and basically used for designing in android. All the elements of the linear layout are displayed in a linear fashion. In general, there child/elements displayed according to orientation. The orientation would be either vertical or horizontal as per need.
Types Of Linear Layout Orientation.
There are two types of orientation
All the elements are arranged vertically in a line one after another. In below code snippet you will see how to use it.
All the elements are arranged horizontally in a line one after another. In below code snippet you will see how to use it.
Main Attributes in Linear Layout.
The gravity attribute is an optional attribute. Like the left, right, centre, top, bottom etc.
we have set gravity centre for linear layout. So the buttons get align to the middle in a vertical orientation in our layout, see below code snippet.
The android:layout_weight attribute assign how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value. And then any remaining space in the view group is assigned to children in the proportion of their declared weight. The default weight is zero.
Weight property for a button in a linear layout. In the below example one button is of weight 3 and other is of weight 1.
android:weightSum attribute is the sum-up of all the child attributes weight. We need this attribute to define the weight property of the children.
THANK FOR READING THIS BLOG STAY SAFE AND KEEP CODING
CONNECT WITH THE AUTHOR ON LINKEDIN.
VISIT OUR WEBSITE BRIGHTERBEES FOR MORE INTERESTING STUFFS ABOUT ANDROID DEVELOPMENT.
IF YOU WANT TO KNOW ABOUT XML IN ANDROID click here.