I had a similar problem and decided to override it onMeasure RelativeLayout method.
package com.etsy.android.grid.util; import android.content.Context; import android.util.AttributeSet; import android.widget.RelativeLayout; public class DynamicHeightRelativeLayout extends RelativeLayout { public DynamicHeightRelativeLayout(Context context) { super(context); } public DynamicHeightRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); } public DynamicHeightRelativeLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Then I used this class in the XML layout file:
<?xml version="1.0" encoding="utf-8"?> <com.etsy.android.grid.util.DynamicHeightRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" ... /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" ... /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" ... /> </com.etsy.android.grid.util.DynamicHeightRelativeLayout>
source share