tags:

views:

1950

answers:

3

Is there Any way to set the width of the Layout.

Because most of the time it doesn't work?

+2  A: 
<WhateverLayout ... android:layout_width='xxxdip' />
stevedbrown
but how to do it programitically without using xml
raj
+3  A: 

Try adding the layout_width or width attributes to your layout. Example:

<LinearLayout android:layout_width="100dip" android:layout_height="100dip" />
Isaac Waller
This won't work unless it's prefixed with "android:".
stevedbrown
Sorry - fixed that.
Isaac Waller
+3  A: 

If you're doing it the XML way you'd use the layout_width attribute:

<LinearLayout
    android:layout_width ="100dp"
    android:layout_height="wrap_content" />

If you're doing it programatically you'd use the LayoutParams:

LinearLayour ll = new LinearLayout(this);
parentView.addView(ll, new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT));
fiXedd
thanks.Can we fixed a child in a particular Layout.I have a relative Layout .Under that I have taken one linear Layout and and a button horizontically.I have also set the width of the linear Layout.but the button appear at the first place.I want this button at the end.
raj
In that case you'd use one of the alternate addView() methods... for example addView(View child, int index, LayoutParams params). See (ViewGroup)[http://developer.android.com/reference/android/view/ViewGroup.html] for a full listing.
fiXedd
Thanks a lot
raj