2012-07-31 19 views
0

我知道這有點奇怪,但忍受着我。TabHost - 對齊底部,禁用並顯示無視圖

我有一個自定義視圖,它擴展了TabHost並擴充了XML。它包括幾個視圖,它與底部對齊,一切都很好。

問題是,當我把TabHost放在不同的活動中,我不想看到任何TabHost視圖。只有活動佈局頂部的TabHost選項卡。基本上,我希望TabHost作爲一個禁用的底部欄在那裏。

這裏的TabHost XML(它的偉大工程,對準底部,只要我的自定義視圖之一之間切換):

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      > 

      <CustomView#1 
       android:id="@+id/tab_watch_me" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <CustomView#2 
       android:id="@+id/tab_messages" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <CustomView#3 
       android:id="@+id/tab_search_results" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <CustomView#4 
       android:id="@+id/tab_my_profile" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <CustomView#5 
       android:id="@+id/tab_user_profile" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" /> 
    </LinearLayout> 

</TabHost> 

這裏的活動XML(我不想要的要顯示的tabhost意見,只對準tabhost按鈕底部):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <customview.HeaderView 
     android:id="@+id/header_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

**//Notice that I don't want to show any of the customViews the tabhost hold. only the tabhost tabs/buttons** 

    <customview.MyTabHost 
     android:id="@+id/settings_tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

讓我知道如果你爲了幫助需要更多的代碼!

謝謝!

+0

所以你想讓它在那裏,但什麼也不做,沒有互動性,對嗎? – Rick 2012-07-31 18:12:37

+0

@Rick聽起來很奇怪,是的。我設法用RelativeLayout來做到這一點,但我不想使用該解決方案。 – 2012-07-31 18:14:57

+0

也許您可以在選項卡選擇發生時通過代碼添加您的自定義內容視圖? – CSmith 2012-07-31 18:20:06

回答

0

我的RelativeLayout解決方案,如果這有助於任何人。如果有人願意提供,我仍然在尋找更好的解決方案。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <customview.HeaderView 
     android:id="@+id/header_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 

<Any other view 
android:layout_below="@+id/header_view" 
/> 

    <customview.MyTabHost 
     android:id="@+id/settings_tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" /> 

</RelativeLayout>