1

嘿,我有一個標籤主機,我想當我點擊一個標籤顯示一個文本。我已經在該類調用的相應xml文件中聲明瞭文本。如何在<TabHost>標籤內顯示文字? Android

這裏是xml文件:

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

而且我寫這樣的消息對類:

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

但它不會顯示任何東西。爲什麼?

回答

2

這是因爲你的FrameLayout高度設置爲fill_parent,所以它填滿了屏幕,將你的文本視圖推出窗口。

圍繞它的方法是將高度設置爲0dip,然後給它一個layout_weight =「1」,但不給textview或tabwidget任何重量屬性。

相關問題