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の高さは、そのウィンドウの外にあなたのTextViewを押して画面を埋めるようfill_parentに設定されているので。

それを回避する方法は0dipする高さを設定し、それにlayout_weight =「1」を与えるが、TextViewのかtabwidgetに任意の重量属性を与えていないことです。

関連する問題