2013-04-01 54 views
2

我想建一個垂直製表主機像下面的圖片的Android垂直tabhost

enter image description here

我試着用下面的代碼,但該選項卡不可見

getTabWidget().setOrientation(LinearLayout.VERTICAL); 

是有可能實現像下面的標籤主機。如果可能告訴我實現標籤主機像下面的方式,併發布鏈接,如果有任何內置的項目來實現它像下面的圖像。 (或) 是它可以添加到圖像視圖點擊類似於標籤欄中選擇一個活動點擊如下圖所示

mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1)); 

,因爲如果有可能,我要把圖像視圖,並更改活動在每個項目上點擊

幫助我製作垂直製表符主機。

回答

3

你只需要放置在你的XML文件中的水平LinearLayout您的標籤控件:

<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/imageView3" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0"/> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 
     </android.support.v4.view.ViewPager> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_gravity="center_vertical"> 
     </TabWidget> 

    </LinearLayout> 
</TabHost> 

,如果你想要它,這將標籤放置到內容的右側,左側則需要重新排列XML文件中的順序。

+1

是viewpager和FrameLayout裏甚至要求? –

1

更好地使用片段。使用垂直對齊的按鈕進行佈局,並使用片段在單擊按鈕時轉換頁面。 Refer this瞭解更多關於碎片。

0

只是爲了補充Emil Adz的答案。

當您使用圖形工具將控件添加到佈局時,它會添加所需的所有代碼,但它會錯過每個LinerLyout的android:orientation="vertical"

例子:

<LinearLayout 
       android:id="@+id/tab1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       > 
      </LinearLayout> 

您必須鍵入下來自己

<LinearLayout 
       android:id="@+id/tab1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 
      </LinearLayout>