3

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: enter image description here

I want to split those vertically, so it will scale nice.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Lijap
  • 625
  • 3
  • 7
  • 23
  • if u use weight= 1 in all ur nested layouts,, it will result showing all layouts one after other, but all will be visible on the screen – AAnkit Jul 06 '12 at 19:58
  • Better you post your xml, how it look like and how you wanted it to be.. Someone can change accordingly – AAnkit Jul 06 '12 at 19:58

2 Answers2

1

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.

Aqif Hamid
  • 3,511
  • 4
  • 25
  • 38
  • Will this make them split it ONLY vertically? I already have them set to be fill_ parent in width, and I want to split the height of the screen between them. – Lijap Jul 06 '12 at 20:01
  • if your parent layout orientation is horizontal, it will lay them out horizontally. – Aqif Hamid Jul 06 '12 at 20:09
1

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

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
  • 1
    I always found this example contrived, wrong even. The two layouts posted there are *not* equivalent. In the RelativeLayout, he fixes the height of one TextView to 26dp. However, the original task was to allocate space equally among the two TextViews, regardless of the container size. These two layouts are simply not equivalent ergo the latter doesn't actually replace the former. – mxk Nov 27 '12 at 20:47