In your code you are setting the layout params of the LinearLayout
itself. Instead, you need to create a new set of LayoutParams for each
button and give each of them the weight you want.

On Mon, Oct 12, 2009 at 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
> >
>



-- 
Romain Guy
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to