2014-02-24 23 views
0

我想設置的選項卡host.in標籤滾動條也爲五片,但我想在一個時間顯示只有三個 標籤,以及如何使滾動條爲使標籤能滾動查看更多選項卡......請給我提供了一些解決方案.......如何設置選項卡主機滾動條

這爲m的xml文件.....

<RelativeLayout 
    android:id="@+id/rl3" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <TabHost 
     android:id="@+id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="@drawable/gray" > 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

      <RelativeLayout 
       android:id="@+id/layTab" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerVertical="true" 
       android:gravity="center" > 

       <HorizontalScrollView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:fillViewport="true" 
        android:scrollbars="none" > 

        <TabWidget 
         android:id="@android:id/tabs" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" > 
        </TabWidget> 
       </HorizontalScrollView> 
      </RelativeLayout> 

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

       <fragment 
        android:id="@+id/fragment1" 
        android:name="info.tech.slidermenu.Home_feed" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginTop="50dp" /> 

       <fragment 
        android:id="@+id/fragment2" 
        android:name="info.tech.slidermenu.Upcoming_tennise_match" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginTop="50dp" /> 

       <fragment 
        android:id="@+id/fragment3" 
        android:name="info.tech.slidermenu.Upcoming_tennise_match" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginTop="50dp" /> 

       <fragment 
        android:id="@+id/fragment4" 
        android:name="info.tech.slidermenu.Upcoming_tennise_match" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginTop="50dp" /> 

       <fragment 
        android:id="@+id/fragment5" 
        android:name="info.tech.slidermenu.Upcoming_tennise_match" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginTop="50dp" /> 
      </FrameLayout> 
     </RelativeLayout> 
    </TabHost> 
</RelativeLayout> 

這是類文件....

public void tabselect() { 
    TabHost tab = (TabHost) findViewById(R.id.tabhost); 
    tab.setup(); 
    tab.setHorizontalScrollBarEnabled(true); 
    TabHost.TabSpec spec = tab.newTabSpec("tab1"); 
    spec.setContent(R.id.fragment1); 
    spec.setIndicator("Feed"); 

    tab.addTab(spec); 
    spec = tab.newTabSpec("tab2"); 
    spec.setContent(R.id.fragment2); 
    spec.setIndicator("tennis"); 
    tab.addTab(spec); 

    spec = tab.newTabSpec("tab3"); 
    spec.setContent(R.id.fragment3); 
    spec.setIndicator("boxing"); 
    tab.addTab(spec); 

    spec = tab.newTabSpec("tab3"); 
    spec.setContent(R.id.fragment4); 
    spec.setIndicator("cricket"); 
    tab.addTab(spec); 

    spec = tab.newTabSpec("tab3"); 
    spec.setContent(R.id.fragment5); 
    spec.setIndicator("base ball"); 
    tab.addTab(spec); 

    tab.setCurrentTab(0); 

} 

截屏....

enter image description here

+0

如果你還沒有走你的代碼。我建議使用View Pager和PageStrip。它們通過翻轉屏幕來提供滾動,另外它還使用片段以及TabHost也被棄用。 http://howrobotswork.wordpress.com/2013/06/22/how-to-use-the-pagertabstrip-and-the-pagertitlestrip/你一定會得到更多的例子ob PageStrip。只是谷歌。 :) –

+0

你能幫助我如何使用它與此代碼.. – bhavdip

+0

請實施一個fragmentTab,你使用的代碼將不會感覺好,一旦你前進的工作。 http://www.codeproject.com/Articles/678093/Fragments-Creating-a-Tabbed-Android-User-與您不必擔心屏幕大小的片段接口,您的選項卡將自動調整。 – Skynet

回答

1

您已經使用了TabWidget一個HorizontalScrollView,所以這是正確的方式。如果你不能這樣做,可能你會遇到佈局問題。

你沒有詳細說明你是否在爲你的TabWidget使用自定義佈局,但如果不是,這將是一個很好的方法來實現你想要的,因爲沒有方法可以說「我只想顯示一次3個標籤「。

簡單地定義你的標籤一個新的佈局,使三者合計適合屏幕的寬度,其餘的將通過滾動可到達。

---- ----編輯

我看到你的代碼非常LinearLayout秒。試試這樣的:

<LinearLayout 
      android:id="@+id/TabContainer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="99" 
      android:orientation="vertical"> 
    <TabHost 
      android:id="@+android:id/tabhost" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
    <LinearLayout 
      android:id="@+id/TabLinearLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
     <HorizontalScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:scrollbars="none"> 
     <TabWidget 
      android:id="@+android:id/tabs" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"></TabWidget> 
     </HorizontalScrollView> 
     <FrameLayout 
      android:id="@+android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="10dp" /> 
    </LinearLayout> 
    </TabHost> 
</LinearLayout> 
+0

在這種方法中標籤根本不可見.. 。 – bhavdip

+0

查看我的更新回答。 – nKn

相關問題