Using ViewStub with Tabs in Android Layout
I have read http://developer.android.com/resources/articles/layout-tricks-stubs.html which explains how to use a viewstub as a lazy include for layouts.
This works fine on a simple list view i have, but when I try to use it in my actual Tabbed layout, it disappears as soon as the tab gets any real content.
I have set all tabs, and tab host to use wrap_content as height (so as not to push the stub off)
Has anyone used stubs with a tabbed view? What is the trick?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView android:id="@+id/discqueue" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView android:id="@+id/instantqueue"
android:layout_width="fill_parent" android:layout_height="wrap_content" /开发者_运维百科>
</FrameLayout>
<ViewStub android:id="@+id/stub_navigate"
android:inflatedId="@+id/panel_navigate" android:layout="@layout/pagination_bar"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</LinearLayout>
</TabHost>
</LinearLayout>
Figured it out!
The trick they don't mention on the developer site is that for list/grid type dynamic views you actually want to merge an existing view with any stubs, rather than inserting stubs into your view, like so;
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<include android:id="@+id/cell3" layout="@layout/queue_man" android:layout_height="40dp" android:layout_gravity="bottom" />
<ViewStub
android:id="@+id/stub_navigation"
android:inflatedId="@+id/panel_navigation"
android:layout="@layout/pagination_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</merge>
This of course leaves cupcake and donut users in the dust though.
精彩评论