I have a listview with custom rows. In the row there are these items:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView1"
android:layout_width="10dp"
android:layout_height="fill_parent"
android:focusable="false"
android:scaleType="fitXY">
</ImageView>"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textsll"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_marginLeft="5dp">
<TextView android:id="@+id/textView1"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:maxLines="1"
android:ellipsize="end">"
</TextView>
<TextView android:id="@+id/textView2"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignParentBottom="true"
android:layout_below="@+id/textView1"
android:maxLines="1"
android:ellipsize="end">
</TextView>
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textsll2"
android:layout_gravity="center_vertical|right"
android:layout_marginLeft="10dp">"
<TextView android:id="@+id/textView3"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:paddingBottom="5dp"
android:maxLines="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:background="#87EB81">
</TextView>
</LinearLayout>
</LinearLayout>
If both textviews has some content, they are centered vertically in the row (almost).
But if the lower textview is empty, I call:
holder.textView2.setVisibility(View.INVISIBLE);
holder.textView.setGravity(Gravity.CENTER_VERTICAL);
Still, the upper textview gets into the top of the row. Why?

If I set it to View.GONE, I get this, but I dont want the height of the row to change:

Update:
In a
RelativeLayout, views are aligned with their parent, with theRelativeLayoutitself, or with other views. For instance, we declared that the description is aligned with the bottom of theRelativeLayoutand that the title is positioned above the description and anchored to the parent’s top. With the description GONE,RelativeLayoutdoesn’t know where to position the title’s bottom edge. To solve this problem, you can use a very special layout parameter called layout_alignWithParentIfMissing.This
booleanparameter simply tellsRelativeLayoutto use its own edges as anchors when a constraint target is missing. For instance, if you position a view to the right of a GONE view and setalignWithParentIfMissingto true,RelativeLayoutwill instead anchor the view to its left edge. In our case, usingalignWithParentIfMissingwill causeRelativeLayoutto align the title’s bottom with its own bottom.For more look at Layout Tricks: Creating Efficient Layouts