Introducing Linear Layout

 

Linear Layout

It is a layout in which all elements or children are aligned in a horizontal or vertical manner. It is a quite basic layout which offers clean arrangement and direct with code build.

It means if we set orientation as vertical it means it means there will be only one child in a single row irrespective of its height or width and similarly for horizontal, it will be arranged only in one row high. A linear layout respects margins between children and the gravity (right,center or left alignment) of each child.

Layout Weight

Linear layout also provides assigning a weight to individual children with the

android:layout_weight. it basically gives the importance value to a view in terms of how much space it should occupy on the screen.

Layout Paramenters

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"

 

Now in above give xml code to create a simple text view which shows hello world as shown. Now here we have used basic fundamental attributes like layout_width and height their values can be arranged as px (size) but here we have written match_parent for layout_width now match parent means the area occurred by the text view will be equal to the display width as shown in image,

now wrap_content is basically arrange the size of the child according to the content in the element. It can easily understood by the shown image.

When you will adjust the text view attributes as shown you will definitely realize the difference between attributes. Try to create changes by your self to know in detail about the different attributes.

In upcoming posts you will find more about linear layout and different elements and how to use them. There our also other bunch of layouts available in android like flow layout and constraint layout we will discuss it later.

 

 

About kaushal97

Android Enthusiast

Leave a Reply

Your email address will not be published.