2011-09-02 3 views
1

J'ai une TabActivity avec des TabWidgets personnalisés en bas. Je veux être en mesure d'ajouter plus de 5 onglets. Contrairement au MenuBar, qui ajoute dynamiquement un bouton "more", les Tabs sont juste redimensionnés et ont l'air horriblement. Donc, ma première tentative a été d'enrouler mes TabWidgets dans un HorizontalScrollView. Le problème est, que j'ai un ListView comme TabContent et son dernier élément semble être caché derrière mon TabWidgets. Telle est la mise en page pour mon TabViewHorizonatalScrollView sur TabWidged "vole" l'espace

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_linlay_parent" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <RelativeLayout 
     android:id="@+id/main_tablinear" 
     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_alignParentTop="true" 
     android:layout_above="@android:id/tabs"/> 
     <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 
     android:scrollbars="none" 
     android:layout_alignParentBottom="true"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center"/> 
     </HorizontalScrollView> 
    </RelativeLayout> 
    </TabHost> 
</LinearLayout> 

je fais quelque chose de mal dans ma mise en page? Existe-t-il de meilleurs moyens d'appliquer plus de 4 onglets? Bien que je puisse voir 4 Tabs bien avec mon Nexus-S, je pense qu'ils sont déjà laids sur un Wildfire. Toute idée appréciée

+0

Est-ce qu'il commence seulement à défiler si vous ajoutez plus de 4 onglets? Le mien a 5 onglets et il comprime tout dans ... –

Répondre

0

je me résolu mon problème! Je pense qu'il peut être utile pour les autres utilisateurs de voir la solution:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_linlay_parent" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <RelativeLayout 
     android:id="@+id/main_tablinear" 
     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_alignParentTop="true" 
     android:layout_above="@android:id/tabs" 
     android:layout_marginBottom="50dip"/> 
     <!-- note: margin bottom 50 dip above: 
      its exactly the size of my custom TabWidget --> 
     <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 
     android:scrollbars="none" 
     android:layout_alignParentBottom="true"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center"/> 
     </HorizontalScrollView> 
    </RelativeLayout> 
    </TabHost> 
</LinearLayout> 
0

Essayez ceci. Il a travaillé pour moi:

code:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:layout_width="fill_parent" 
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
<TabHost android:layout_weight="1" android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:orientation="vertical"> 
     <HorizontalScrollView android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <LinearLayout android:layout_height="fill_parent" 
       android:orientation="horizontal" android:layout_width="fill_parent"> 
       <TabWidget android:layout_height="wrap_content" 
        android:id="@android:id/tabs" android:isScrollContainer="true" 
        android:layout_width="fill_parent" android:scrollbars="horizontal"></TabWidget> 
      </LinearLayout> 
     </HorizontalScrollView> 
     <FrameLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent" android:id="@android:id/tabcontent"> 
      <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/tab1"></LinearLayout> 
      <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/tab2"></LinearLayout> 
      <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/tab3"></LinearLayout> 
      <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/tab4"></LinearLayout> 
      <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/tab5"></LinearLayout> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost></LinearLayout> 
+0

Cela a fonctionné pour vous? –

+0

à quoi servent les LinearLayouts avec id/tabX? J'ai ajouté des onglets programmatiques en Java avec TabSpecs –

+0

C'était juste un exemple. Bien sûr, vous pouvez les supprimer. –

Questions connexes