Nested Linear Layout Weight
-
19-06-2021 - |
Question
I have one "Master" LinearLayout with several other LinearLayouts nested inside of it that extend all of the way from side to side. I was wondering if I could use weight to split the vertical space up between the nested layouts with the percentage. If so, this could be the solution to all my problems that I am currently having with my app. All help is appreciated!
Here is my goal:
I want to split those vertically, so it will scale nice.
Solution
weight of your parent Layout
will be count of your total child Layouts
and give weight=1
to your child Layouts
.
This will align your child Layouts
in equal sizes horizontally.
OTHER TIPS
I would avoid using nested linear layouts. This can severely hinder the apps performance. If you find that you are using several nested linear layouts, you might want to consider using a relative layout. Of course, with relative layout's, you can't use the "weight" attribute, but there are ways around that. Here is a great article that talks about layouts:
http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html