2013-06-13 10 views

Antwort

9

Wie wäre ....

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <TabHost 
     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"> 
      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:tag="tab0" 
        android:text="Tab 1" 
        android:background="@android:drawable/btn_star_big_on" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        /> 
       <TextView 
        android:tag="tab1" 
        android:text="Tab 2" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        /> 
       <TextView 
        android:tag="tab2" 
        android:text="Tab 3" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        /> 

      </TabWidget> 

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

       <TextView 
        android:text="Hallo1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 
       <TextView 
        android:text="Hallo2" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 
       <TextView 
        android:text="Hallo3" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 

      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

</RelativeLayout> 

diese Weise ist es aussehen werden wie folgt:

TabHost

prüfen here die komplette Registerkarte Probe aus.

Hoffe das hilft .... Prost!

+1

das hat nicht für mich funktioniert ... – Supuhstar

+0

@Supuhstar: können Sie erklären, warum oder was für einen Fehler haben Sie? – Trinimon

+5

kein Fehler, nur ... absolut nichts davon hat funktioniert. Die 'TextView's erscheinen links von den Registerkarten in der Vorschau und keine Registerkarten erscheinen, wenn sie auf einem tatsächlichen Gerät ausgeführt werden. Keine Funktionalität wird erhalten und die Fragmente erscheinen übereinander – Supuhstar

1

Sie können immer in die @ + ID/Tab1 gehen und ändern Sie es auf was auch immer Sie die Registerkarte aufgerufen werden soll. Wenn Sie möchten, dass es "About" genannt wird, ändern Sie es einfach zu @ + id/About im linearen Layout für die spezifische Registerkarte.

+0

Die Frage ist über XML. Ist die Formel eine Xpath-Abfrage? Wenn ja, bitte ein Beispiel geben, jeder könnte nicht fließend xpath lesen. –

+2

was ist mit i18n? – gattsbr

+0

Ziemlich spät auf dieser, aber Jorgensen sprach über Tab-IDs, TabHost verwendet standardmäßig Tabs. Aber wie @gattsbr darauf hingewiesen hat, ist diese Lösung nur verwendbar, wenn Sie keine String-Übersetzungsdateien verwenden – STremblay