I have a layout as defined below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical" >
<ImageView
android:id="@+id/movieImageView"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerVertical="true"
android:paddingBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/blank_96_1382x" />
<TextView
android:id="@+id/movieTypeView"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_below="@+id/movieImageView"
android:layout_alignLeft="@+id/movieImageView"
android:maxLines="1"
android:text="Tv Series"
android:textColor="@color/gray"
android:textSize="12sp"
android:gravity="center"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:visibility="gone"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/movieImageView"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/movieTitleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
android:text="Shutter Island starring leonardo di caprio"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold"
android:typeface="sans" />
...
</RelativeLayout>
It would look like this
I want the imageview to shrink based on the contents on the left side of the imageview. For instance if few fields are missing and sum of heights of fields is less than image height then it should shrink (as shown below) .
If sum of heights of the fields on left side of image is greater than specified image height then it should retain the specified height as below
I tried extending imageview and change height/ width of image view reatining the aspect ratio of image as explained here custom image view. But problem is, parent height returned by MeasureSpec.getSize(heightMeasureSpec)
does not return the exact height occupied by fields on the left side (since that will be available only after onMeasure of all child is returned). So this approach did not take me anywhere.
How can I achieve this desired behavior ?