1

Hey, ich habe einen Tab-Host, und ich wollte, dass, wenn ich auf einen Tab geklickt einen Text zeigt. Ich habe den Text in der entsprechenden XML-Datei deklariert, die die Klasse aufruft.Wie zeigt man einen Text in einem <TabHost> Tag? Android

hier ist die XML-Datei:

<?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" 
    android:padding="5dp"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
    <TextView 
     android:id="@+id/txtView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text=" " 
    > 
    </TextView> 
</LinearLayout> 

Und ich schreibe eine Meldung wie diese auf die Klasse:

txtView = (TextView) findViewById(R.id.txtView);   
txtView.setText("This is rated calls"); 

Aber es zeigt nichts. Warum?

Antwort

2

Da Ihre FrameLayout-Höhe auf "fill_parent" gesetzt ist, füllt sie den Bildschirm aus, sodass Ihr Textansicht nicht mehr angezeigt wird.

Der Weg herum ist es, die Höhe auf 0dip und geben Sie ihm dann ein Layout_weight = "1" aber geben Sie keine Gewichtsattribut der Textansicht oder Tabwidget.

Verwandte Themen