2010-01-30 53 views
0

我已閱讀http://developer.android.com/resources/articles/layout-tricks-stubs.html,其中介紹瞭如何將viewstub用作佈局的懶惰包含。將ViewStub與Android佈局中的選項卡一起使用

這對我有一個簡單的列表視圖很好,但當我嘗試在我的實際選項卡式佈局中使用它時,只要選項卡獲取任何實際內容,它就會消失。

我已經設置所有選項卡,並使用WRAP_CONTENT爲高(從而不推存根關)

有沒有人使用標籤視圖存根接頭主機?有什麼竅門?

<?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> 
+0

也許這也與列表有關 - 如果我將項目數量限制爲5個左右,則導航欄會保留,一旦超過它就會被取消。 – Eddie 2010-01-30 14:36:14

回答

2

想通了!

他們在開發人員網站上沒有提到的技巧是,對於列表/網格類型動態視圖,您實際上想要將現有視圖與任何存根合併,而不是將存根插入視圖中,如此;

<?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> 

這當然會讓蛋糕和甜甜圈的使用者留在塵土中。

+0

你能解釋一下這個furthur嗎? – 2011-03-04 05:02:29

+0

Sweety - 我的答案中的代碼將我的問題中的原始佈局與新佈局中定義的新視圖(viewstub)合併。因此,2個文件(只包含內部內容的標籤視圖)和合並文件(即將存根引入標籤之下)。在你的代碼中你調用合併的佈局。 – Eddie 2011-03-09 18:15:42

相關問題