2012-08-10 18 views
12

Ich habe eine Registerkarte Host, in dem ich mehr als 6 Tasten haben. Der Bildschirm zeigt jedoch nur 3-4 Tasten.Hinzufügen von Bildlauf in Tabhost in Android

Folgendes ist der Code, den ich zusammen mit dem Bild verwende.

<?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" 
    android:background="#777777"> 

    <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:gravity="center" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:background="@drawable/navbar_background" 
      android:layout_alignParentBottom="true" 
      android:layout_centerVertical="true" 
      > 
      <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      /> 
     </RelativeLayout> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_above="@+id/layTab"/> 


    </RelativeLayout> 
</TabHost> 

enter image description here

Die Frage ist, wie ich glaube, eine Rolle fügen, so dass ich bis alle Tasten 6 oder einem anderen Trick bewegen kann.

Mit freundlichen Grüßen

Antwort

23

Gerade Nest der TabWidget in einem HorizontalScrollingView, wie folgt aus:

<?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" 
    android:background="#777777" > 

    <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:background="@drawable/navbar_background" 
      android:gravity="center" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" > 

      <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> 
     </RelativeLayout> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_above="@+id/layTab" 
      android:layout_alignParentTop="true" /> 
    </RelativeLayout> 

</TabHost> 

By the way, diese Lösung funktioniert für viele andere Szenarien, Radiogroup, zum Beispiel

+0

nicht für die Arbeit dies, ich brauche keine Radio-Gruppe: d –

+0

Ja, ich habe es falsch gemacht. Das TabWidget muss verschachtelt sein ... Ich habe meine Antwort bearbeitet. Versuchen Sie es jetzt –

+0

Ist es auch notwendig, die HorizontalScrollView in zwei RelativeLayouts zu verschachteln? Meine Verschachtelung geht wie folgt: Relative> TabHost> Linear> Horizontal> TabWidget und es scrollt nicht. Glauben Sie, dass sich die API seit 2012 verändert hat? – James

Verwandte Themen