I have a ViewStub inside a DrawerLayout, and I plan to inflate and remove this stub dynamically according to the needs of the user.
The drawer consists of a RelativeLayout containing: 1. A TextView 2. The mentioned ViewStub 3. A ListView
When I inflate the ViewStub, the resulting view does not displace the ListView. Instead, it's inflated underneath the ListView, in such a way that the user can't see it. I would like for the stub to push the list down when it is inflated.
How can I solve this?
Here is the XML code:
<RelativeLayout
android:id="@+id/drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#dedede"
android:fitsSystemWindows="true"
android:orientation="vertical"
>
<TextView
android:id="@+id/drawer_text"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/holo_red_light"/>
<ViewStub
android:id="@+id/info_stub"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout="@layout/info_entry_stub"
android:layout_below="@+id/drawer_text"/>
<ListView
android:id="@+id/drawernavlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_dark"
android:layout_below="@+id/info_stub"
android:layout_gravity="start">
</ListView>
</RelativeLayout>
The layout the stub points to:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/info_entry_stub">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:text="HELLO"/>
</RelativeLayout>
SOLUTION FOUND: I solved it by adding inside the ViewStub the attribute:
android:inflatedId="@id/info_stub"