webnovel

linear layout

Linear Layout & Relative Layout In Android | Android Tutorials in Hindi #3

When to use a Linear Layout in Android Studio?

Use Linear Layout when you want group of widgets to be aligned in one direction. Linear Layout will be an ideal choice while designing a form.

There are two types of linear layout orientatons: vertical orientation and horizontal orientation. Linear layout also supports layout_weight attribute for its children individually (each child has its own layout_weight attribute), larger the value of a widget's  layout_weight more will be the space taken by that widget.

When to use a Relative Layout in Android Studio?

Use Relative Layout when you want  widgets to be in a relative position to siblings (other widgets within the same relative layout). Relative layout is a bit complex to use and is not used by developers these days.

Which of the layouts (Linear/Relative/Constraint) is better?

Each Layout has its own benefits but when it comes to dynamic and responsive views you should always choose Constraint Layout. Constarint Layout was added to Android Studio 2.2 in 2016 and it became the default layout of Android Studio because of its simplicity and ease of creating complex layouts.

Layout margin is the difference between space outside  boundaries of the Layout and the screen.

Padding refers to the space between the elements and Layout or among different elements .

marginLeft – distance from left side of the view

marginRight – distance from the right side of the view

marginTop – distance from the top of the view

marginBottom – distance from bottom of the view

Padding is the difference within the boundaries of layout.

Measurement  units used in margin and padding are dp (density independent pixels)  and sp (Scale independent pixels).