2011-08-18 132 views
0

我有一個tabhost,其中包含三個製表符,並與三個活動相關聯。所有三個標籤都位於上方。我怎樣才能使這三個標籤在底部?如何在底部添加製表符

我發現這個,但仍然有一些問題。

這是我tabhost XML文件:

<?xml version="1.0" encoding="UTF-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 
    </LinearLayout> 
</TabHost> 

在我TabActivity類,我有以下代碼:

setContentView(R.layout.tabs); 

TabHost mTabHost = (TabHost)findViewById(android.R.id.tabhost); 

mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class))); 
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class))); 
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class))); 

mTabHost.setCurrentTab(0); 

有一個名爲TabActivity1一個活動,我也包括在清單文件。但它顯示的錯誤:

Can't get the activity TabActivity1.

+0

您是否在Manifest文件中包含了AndroisTabViewActivity?請說明您收到了哪種錯誤。也許它甚至與註冊清單中的活動無關。 – Kostas

+0

是的,我把它包含在清單文件中。我不知道如何讓你的日誌貓圖片。所以我會寫錯誤。只需等待。 –

+0

這裏是我的錯誤:無法啓動activityComponentInfo {com.mirza.tabViewDemo/com.mirza.tabViewDemo.AndroisTabViewActivity}:android.content.ActivityNotFoundException顯式活動類{com.mirza.tabViewDemo/com.mirza.tabViewDemo.TabActivity1} –

回答

1

我假設你想顯示 「選項卡」 窗口底部,只是試試這個:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:id="@+id/linearLayout1" 
    android:layout_height="match_parent"> 

    <TabWidget 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@android:id/tabs" 
     android:layout_alignParentBottom="true"> 
    </TabWidget> 

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

+0

Thanks.Your code也起作用,我也是。我只是在清單文件中輸入錯誤。我輸入了活動而不是活動。讓所有人蔘與。 :d –

0

如果您想使用LinearLayout

<?xml version="1.0" encoding="UTF-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</TabHost> 

有了這個解決方案,tab content將沒有空間首先,TabWidget將自己的空間,那麼剩下的空間將被給予tab content