Q:

wrap_content does not work with custom RelativeLayout

I have created a custom layout which extends RelativeLayout. At the moment, this layout does nothing except overriding the onMeasure method (that I will need later). Here is my code:
public class CustomLayout extends RelativeLayout {

    public CustomLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    }
}

And I have the following layout file:
   <LinearLayout
        android:id="@+id/containerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        android:orientation="horizontal" >

        <...CustomLayout
            android:id="@+id/item"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:background="#fff" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello"
                android:textSize="20sp" />

        </...CustomLayout>

        <RelativeLayout
            android:id="@+id/controls"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="50"
            android:background="#0f0" >
        </RelativeLayout>
    </LinearLayout>

The problem is that the height is null. During my debugging, I have noticed that if I change the CustomLayout to a RelativeLayout it works.
So, it is quite obvious that the problem comes from my CustomLayout, but what do I need to add to make the wrap_content work ?

A:

I have finally found the problem. I change this:
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
 }

To this:
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }

And it works fine.
Explanation
First, the following line was useless:
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);

But why does it makes the View's height null?
In fact, I misunderstood the paramaters of the onMeasure method. They are MeasureSpec values. Here is what Google says about this object:

A MeasureSpec encapsulates the layout requirements passed from parent
  to child. Each MeasureSpec represents a requirement for either the
  width or the height. A MeasureSpec is comprised of a size and a mode.
  There are three possible modes:
UNSPECIFIED The parent has not imposed any constraint on the child. It
  can be whatever size it wants. EXACTLY The parent has determined an
  exact size for the child. The child is going to be given those bounds
  regardless of how big it wants to be. AT_MOST The child can be as
  large as it wants up to the specified size. MeasureSpecs are
  implemented as ints to reduce object allocation. This class is
  provided to pack and unpack the  tuple into the int

The widthMeasureSpec and heightMeasureSpec values are not only the width and the height of the View. In this case, passing these values to setMeasureDimension are completly wrong because this method actually requires real sizes as parameters.

