2012-06-05 3 views
4

Я хочу показать вкладки шириной горизонтальной полосы прокрутки. Я попытался реализовать так: How do you set tab view to scroll?TabWidget не заполняет HorizontalScrollView

Но вкладки не заполняют ширину.

Как это исправить?

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

     <HorizontalScrollView 
      android:id="@+id/horizontalScrollView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

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

       <TabWidget 
        android:id="@android:id/tabs" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" > 

       </TabWidget> 

      </LinearLayout> 
     </HorizontalScrollView> 

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

     </FrameLayout> 

    </LinearLayout> 

    <ProgressBar 
     android:id="@+id/destinationProgressBar" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" /> 

</TabHost> 

enter image description here

+0

Пожалуйста см см эту ссылку http://stackoverflow.com/questions/1117641/how-to-use-a-tab-widget-in-android – DynamicMind

+0

... Моя проблема связана с ScrollView. :( – Emerald214

ответ

6

решаемые его! Используйте android: fillViewport = "true" и удалите 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"> 

     <HorizontalScrollView 
      android:id="@+id/horizontalScrollView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true"> 

       <TabWidget 
        android:id="@android:id/tabs" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" > 

       </TabWidget> 

     </HorizontalScrollView> 

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

     </FrameLayout> 

    </LinearLayout> 

    <ProgressBar 
     android:id="@+id/destinationProgressBar" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" /> 

</TabHost> 
+1

отлично ... проверьте свой ответ как принято! – GAMA

+0

Сколько вкладок необходимо вставить до начала прокрутки? –

Смежные вопросы