I have a layout problem with my custom viewgroup class. 

I call init() in the constructor. In my init() function I inflate the viewgroups layout from an xml file, which contains a LinearLayout to which I add several other views. 

I am using spacer (View layout\_width="0" and layout\_weight="1") to distribute the items equaly. 

The problem lies here: the layout still has not defined any width when i add the children. So the spacer all have the size 0, and wont actually place the "line\_dot" items equally. How can i somehow update their size?

```
public class SliderSwitch extends FrameLayout {

...
    public SliderSwitch(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context)
    {
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.slider_switch,this);

        sliderLayout = (LinearLayout) findViewById(R.id.sliderLayout);
        labelLayout = (LinearLayout) findViewById(R.id.labelLayout);

        // add one spacer
        View spacer = (View) inflate(context,R.layout.spacer, null);
        sliderLayout.addView(spacer);

        // setup the view depending on how many elements there are
        for (int i=1;i<numberOfElements-1;i++) {

            ImageView lineDot = (ImageView) inflater.inflate(R.layout.slider_switch_line_dot, null);
            sliderLayout.addView(lineDot);

            View spacer = (View) inflate(context,R.layout.spacer, null);
            sliderLayout.addView(spacer);
        }

    }
... 
}

```

this is the xml file for the spacer:

```
<View
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_weight="1" />

```

and this is the one for my viewgroup layout

```
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/relLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="3dp"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/left_bg" />

            <LinearLayout
                android:id="@+id/sliderLayout"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/middle_bg"
                android:gravity="center"
                android:orientation="horizontal" >

               <!-- <include layout="@layout/spacer"/> -->

            </LinearLayout>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/right_bg" />
        </LinearLayout>

        <ImageButton
            android:id="@+id/sliderKnob"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="0dp"
            android:background="@null"
            android:src="@drawable/knob" />
    </RelativeLayout>

</LinearLayout>

```