2

I've read plenty of questions saying that the problem was the layout_width = 0dip but I've tried that and can't make this work.

I have this holder:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:id="@+id/linearLayout1"
    android:orientation="horizontal"
    android:weightSum="3"
    android:padding="10dip"
    android:fadingEdge="none"
    android:background="@drawable/bg_filters">
</LinearLayout>

And this partials:

<Button
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:layout_width="0dip"
    android:layout_height="40dip"
    android:padding="4dip"
    android:gravity="center"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:layout_marginRight="15dip"
    android:background="@drawable/bg_filter_bt_active"
    android:textColor="@color/app_color_all">
</Button>

but my views' buttons show still show up grouped to the left... Is there a method I should call the holder to recalculate the weights of its children?

Remember, I'm creating them programmatically.

Thanks !

EDIT:

I already HAVE a screen with this composition:

##################################
#                                #
#  Button  |  Button  |  Button  #
#                                #

with that exact XML, but instead of being created programmatically, it is already there in the XML. It works perfectly.

When I create the same setup but programmatically, I get this:

##################################
#                                #
# Button | Button | Button       #
#                                #

The buttons align themselves to the left, even tho the weight should evenly distribute them. Is there a method or something I need to call to the LinearLayout to calculate the weight and correct the view?

EDIT 2:

I just tried taking this same LinearLayout and inserting the same Button 3 times inside it on a regular XML. It shows just like it should. This is definitely something to do with creating the holder and the 3 buttons programmatically.

Draiken
  • 3,805
  • 2
  • 30
  • 48
  • 1
    You can't have 0 width or height. What are you trying to do exactly? – asenovm Sep 30 '11 at 20:21
  • 2
    What are you trying to do exactly? Do you want your button to be the width of the layout? Is your button inside the layout? – digerati32 Sep 30 '11 at 20:24
  • @iLate: A width or height of 0 is possible and used in combination with the `layout_weight` attribute. See the answer to [this question](http://stackoverflow.com/questions/4986861/android-layout-weight) for example. –  Sep 30 '11 at 21:41
  • Post a mockup of how you want it to look please. – Philipp Reichart Sep 30 '11 at 22:29
  • mockup added, and I added the `width = 0` after reading other questions here. It still doesn't matter what I put in there, I've tried and it didn't work – Draiken Oct 03 '11 at 10:59

2 Answers2

0

Have you tried forcing the view to redraw itself through invalidate() or refreshDrawableState()?
Can you post the code where you create those buttons programmatically?

type-a1pha
  • 1,891
  • 13
  • 19
0

Check your imports! I had the same exact problem and it turns out I was importing the wrong LayoutParams. I was importing android.widget.AbsListView, instead of android.widget.LinearLayout.LayoutParams and that what was causing the problem.

Garzahd
  • 5,739
  • 3
  • 18
  • 19