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任何重量属性。