I have a ListView which gets populated with RelativeLayouts. The content of these RelativeLayouts can change and thus change their height respectively. On each RelativeLayou
I had a similar problem with a RelativeLayout inside a ScrollView. According to the documentation there is a bug in RelativeLayout (up to version 17) that cause mistakes in measured height if it is added inside scrolling container (like ListView).
So to solve the problem you should calculate height programmatically.
You could make your extended class and override the onMeasure method or add a OnGlobalLayoutListener to the parent view.
I choose the second way. Here is my solution:

findViewById(R.id.scroll_view).getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
float topElementPosition = findViewById(R.id.top_element).getY();
float bottomElementPosition = findViewById(R.id.bottom_element).getY();
int bottomElementHeight = findViewById(R.id.bottom_element).getMeasuredHeight();
int height = (int)(bottomElementPosition-topElementPosition+bottomElementHeight);
findViewById(R.id.view).setMinimumHeight(height);
findViewById(R.id.scroll_view).getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});