Posted on

Android Nested LinearLayout


android nested linearlayout

Designed by Freepik

Everything or almost everything you can achieve with LinearLayout and FrameLayout. Let’s get a bit deep into LinearLayout

Why LinearLayout

LinearLayout is one of my favorite layouts. It lays out views one after another in order

And same you can do with layout out them horizontally

Nested LinearLayout

Now the reason why you’d put LinearLayout inside another in most cases is if you want to change direction: vertical to horizontal and vice versa

This is really flexible and easy to grasp

Weight

One of the most used attributes with LinearLayout is weight. LinearLayout calculates total weight number by summing all weights of its children and then measures children dimensions by their weight

Dimension that you want to scale you should declare with 0dp value

Beware that there are some drawbacks of having too many nested LinearLayouts with weights. It increases layout measurements dramatically

ConstraintLayout

There’s a newer way to replace all the layouts with just ConstraintLayout. Check this post to learn about it. It’s really fast to create layouts with ConstraintLayout in Design Mode

I still don’t quite like Design Mode, but using ConstraintLayout in XML editor is ugly

It’s still better to start with simple Frame/Linear layouts because they’re specialized and easy to learn, compare to ConstraintLayout

 

Don’t forget to subscribe, follow me on Facebook, Twitter, G+ to get notified about the latest posts!

 

 

 


  • Hi, I’ve started replacing all LinerLayouts and FrameLayouts with the new ConstraintLayout. Yes, the design mode is ugly, but it is easy to do it in the xml editor, if you are familiar with the new ConstraintLayout xml attributes. My idea was to increase the performace of the nested layouts, but after some tests I figured out the performance was not that much better.