I have a Relative Layout with multiple TextView’s inside. This layout has “wrap_content” on its height. When certain navigation buttons are pressed, I change the visibility of the TextView’s, so the desired content is displayed.
However, when the next displayed content is smaller than the previous one, the layout doesn’t shrink, and it leaves plenty of empty space. The layout keeps the height of the largest displayed content, and it stays that way.
I would like to shrink this Layout so it wraps the displayed content, and there’s no extra space left.
Here’s the layout code:
<RelativeLayout
android:id="@+id/brief_box"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#7A08AB"
android:layout_below="@+id/description_navigation">
<ImageView
android:id="@+id/dot_separator_1"
android:layout_height="1dp"
android:layout_width="fill_parent"
android:background="@drawable/dot_separator"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"/>
<TextView
android:id="@+id/brief_about_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@+id/dot_separator_1"
android:layout_marginLeft="20dp"
android:layout_marginRight="14dp"
android:layout_marginTop="4dp"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold"
android:text="Venga a drogarse compipa! Venga a drogarse compipa! Venga a drogarse compipa! Venga a drogarse compipa! Venga a drogarse compipa!"/>
<TextView
android:id="@+id/brief_about_update_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/brief_about_text"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:textSize="12sp"
android:textColor="#DFCAE8"
android:text="Hace 3 horas"/>
<TextView
android:id="@+id/brief_menu_update_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/brief_menu_text"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:textSize="12sp"
android:textColor="#DFCAE8"
android:text="Última actualización hace 2 días."
android:visibility="gone"/>
<TextView
android:id="@+id/brief_menu_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/dot_separator_1"
android:layout_marginLeft="20dp"
android:layout_marginTop="4dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Menú cachero"
android:visibility="gone"/>
<TextView
android:id="@+id/brief_menu_price"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/dot_separator_1"
android:layout_alignParentRight="true"
android:layout_marginTop="4dp"
android:layout_marginRight="10dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="$4.500"
android:visibility="gone"/>
<TextView
android:id="@+id/brief_menu_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@+id/brief_menu_title"
android:layout_marginTop="4dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="bold"
android:text="Fantástico menú que contiene ilimitadas posibilidades de contraer una diarrea que durará mas de una semana. Contiene cochayuyo con guatitas y caca, sopa, ensalada, y bebida."
android:visibility="gone"/>
<TextView
android:id="@+id/brief_where_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/dot_separator_1"
android:layout_marginLeft="20dp"
android:layout_marginTop="6dp"
android:textColor="#FFFFFF"
android:textSize="14sp"
android:text="Encuéntranos en:"
android:visibility="gone"/>
<TextView
android:id="@+id/brief_where_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/brief_where_title"
android:layout_marginLeft="20dp"
android:layout_marginBottom="8dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:text="Lota 3495, Providencia"
android:visibility="gone"/>
<ImageView
android:id="@+id/brief_where_how_to_arrow"
android:layout_width="11dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/dot_separator_1"
android:layout_marginRight="4dp"
android:layout_marginTop="20dp"
android:background="@drawable/arrow_tag"
android:visibility="gone"/>
<TextView
android:id="@+id/brief_where_how_to"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/dot_separator_1"
android:layout_toLeftOf="@+id/brief_where_how_to_arrow"
android:layout_marginTop="16dp"
android:textColor="#FFFFFF"
android:textSize="11sp"
android:textStyle="bold"
android:text="content"
android:visibility="gone"/>
</RelativeLayout>
Here are some screenshots of the issue.
This is the large content:
http://i46.tinypic.com/29xwuw0.png
And this is the small content, with the large content layout:
http://i47.tinypic.com/29gbogm.png
I would appreciate any help.
Be sure to use View.GONE to make a view disappear (and not View.INVISIBLE).
And, when looking at your XML layout, it seems a vertical LinearLayout would be better for what you’d like to accomplish.