I'm going crazy with a layout problem based on the following image

Image represents RelativeLayout. I need the blue view to be aligned with the bottom of the black. BUT, if the black look is shorter than the sum of the red and blue, I need the blue look to be below the red. I want to get this result:

I tried with the following xml:
<RelativeLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:id="@+id/blackView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:align_parentTop="true"
android:align_parentLeft="true"/>
<View
android:id="@+id/redView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:align_parentTop="true"
android:align_parentRight="true"
android:layout_toRightOf="@+id/blackView"/>
<View
android:id="@+id/blueView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/blackView"
android:layout_below="@+id/redView"
android:layout_alignParentRight="true"/>
</RelativeLayout>
but it seems that layout_alignBottom takes precedence over layout_below. I also tried to set blueView to match the bottom of its parent, but the result is that the parent (having a height wrap_content) gets tall as its own parent (the entire height of the screen).
Has anyone had the same problem?