What you want is: LayoutParams lp = new LinearLayout.LayoutParams(width, height, weight);
On Oct 12, 11:16 am, Nitin67 <[email protected]> wrote: > Hello, > > I am also trying to set the weight using api calls. > > I have a LinearLayout, and I want to put a row of MyButtons in it, > and I want them to space themselves out. Instead they bunch up on the > left side of the row, and leave a large empty space on the right. > > I see that the LayoutParams object has a weight field. But how do > I set it for each MyButton ? I have tried different combinations, but > no luck. > > public class ButtonArea extends LinearLayout { > > setOrientation(LinearLayout.HORIZONTAL); > LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT); > setLayoutParams(lp); > > for(int i = 0; i < altButtons.length;i++) { > altButtons[i] = new MyButton( height, width ... ); > addView(altButtons[i]); > } > > } > > Thanks ! > Nitin > > On Sep 7, 9:34 pm, Mark Murphy <[email protected]> wrote: > > > slv wrote: > > > Hello, > > > is there a way to set theweightof a view usingAPIcalls? I > > > construct parts of my UI at runtime. The dynamic UI has multiple View. > > > However, I want to set theweightof those view to be non-equal. Any > > > idea on how to do that? > > >http://developer.android.com/reference/android/widget/LinearLayout.La... > > > See the layout_weight field. > > > -- > > Mark Murphy (a Commons > > Guy)http://commonsware.com|http://twitter.com/commonsguy > > > Android Development Wiki:http://wiki.andmob.org > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

