This is how my layout looks. And the respective code for the same is given below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="280dp"
card_view:cardElevation="8dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/postTime"
android:layout_above="@+id/linearLayout"
android:layout_alignParentEnd="true"
android:layout_marginEnd="15dp"
android:layout_marginBottom="14dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="0"
android:id="@+id/score"
android:layout_marginEnd="20dp"
android:layout_alignParentTop="true"
android:layout_alignEnd="@+id/postTime"
android:layout_marginTop="34dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/postText"
android:layout_marginLeft="20dp"
android:gravity="center"
android:layout_alignBottom="@+id/postTime"
android:layout_alignParentLeft="true"
android:layout_toStartOf="@+id/likes"
android:layout_alignTop="@+id/score" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0 likes"
android:id="@+id/likes"
android:layout_marginTop="19dp"
android:layout_below="@+id/score"
android:layout_alignEnd="@+id/postTime" />
<LinearLayout android:layout_alignParentBottom="true"
android:layout_marginBottom="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/linearLayout">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/plusTwoButton"
android:src="@drawable/fab_shadow_mini"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="5dp"
android:background="@drawable/button_border"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/plusOneButton"
android:layout_marginBottom="5dp"
android:src="@drawable/fab_shadow_mini"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/button_border"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/minusOneButton"
android:src="@drawable/fab_shadow_mini"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="5dp"
android:background="@drawable/button_border"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/minusTwoButton"
android:src="@drawable/fab_shadow_mini"
android:layout_marginLeft="8dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="5dp"
android:background="@drawable/button_border"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/coName"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/deName"
android:layout_marginTop="5dp"
android:layout_alignBottom="@+id/coname"
android:layout_toEndOf="@+id/coname"
android:layout_marginStart="29dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/deleteButton"
android:layout_alignBottom="@+id/dename"
android:layout_alignRight="@+id/likes"
android:layout_alignEnd="@+id/likes"
android:background="@android:color/transparent"
android:src="@drawable/ic_delete_black_18dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
This layout is fine until the "postText" view's character count is under a certain limit (140). Now I want to accommodate more text to the same layout. Therefore I tried setting the height of the cardview and relative layouts to wrapcontent and setting minHeight on relative layout. As given here .
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="8dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="280dp"
>
Doing this, I get the below result, the postTime and postText views are getting lost. How do I debug this? My goal is to make the cardview grow as the size of the text in postText textview.
Update :
The image showing two cards with texts that exceed the textview and that which is smaller than the textview.
Try this XML layout the CardView will grow with respect to the content Area