what does android:layout_weight="0" mean?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

what does android:layout_weight="0" mean?

Postby sjtcool » Thu Dec 27, 2007 3:57 am

hi,all
When I read the APIDemos example,I find in forwarding.xml, line 27, android:layout_weight="0",
I can't find any instruction about it in the android document, who can tell me what it means?

thx.
sjtcool
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Dec 19, 2007 3:18 am
Location: Nanjing

Top

Postby cabernet1976 » Fri Dec 28, 2007 10:25 am

see here:
http://code.google.com/android/referenc ... out_weight

The default value of layout_weigh is 0
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby cabernet1976 » Fri Dec 28, 2007 10:27 am

update:
:arrow: http://code.google.com/android/intro/tutorial-ex2.html
search "layout_weight" in that page, its description is very detail
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby plusminus » Fri Dec 28, 2007 4:41 pm

Hello sjtcool,

as cabernet1976 linked:

"android:layout_weight" is the factor the view will be stretched, when the parent is larger than its childs in sum.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby guian » Tue Oct 20, 2009 1:56 pm

can we know what is the function to set it programatically ?

setWeight
or setLayoutWeight don't exist... :s
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Postby guian » Tue Oct 20, 2009 2:28 pm

ok guys, found it !

LinearLayout.LayoutParams(width, height, weight);


;)
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Top

Postby rakeshsoni » Wed Mar 03, 2010 7:58 am

LinearLayout supports assigning a weight to individual children. This attribute assigns an "importance" value to a view, and allows it to expand to fill any remaining space in the parent view. Default weight is zero

calculation to assign any remaining space between child

space assign to child = (child individual weight) / (sum of weight of every child in Linear Layout)

Example (1):
if there are three text boxes and two of them declare a weight of 1, while the third one is given no weight (0), then remaining space assign to

1st text box = 1/(1+1+0)
2nd text box = 1/(1+1+0)
3rd text box = 0/(1+1+0)

Example (2) : let's say we have a text label and two text edit elements in a horizontal row. The label has no layout_weight specified, so it takes up the minimum space required to render. If the layout_weight of each of the two text edit elements is set to 1, the remaining width in the parent layout will be split equally between them (because we claim they are equally important).

calculation :
1st label = 0/(0+1+1)
2nd text box = 1/(0+1+1)
3rd text box = 1/(0+1+1)

If the first one text box has a layout_weight of 1 and the second text box has a layout_weight of 2, then one third of the remaining space will be given to the first, and two thirds to the second (because we claim the second one is more important).

calculation :
1st label = 0/(0+1+2)
2nd text box = 1/(0+1+2)
3rd text box = 2/(0+1+2)

Thanks,
Rakesh Soni
rakeshsoni
Freshman
Freshman
 
Posts: 2
Joined: Sat Feb 13, 2010 3:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest