【问题标题】:How to show a text inside a <TabHost> tag? Android如何在 <TabHost> 标签内显示文本?安卓
【发布时间】:2011-05-21 23:16:24
【问题描述】:

嘿,我有一个选项卡主机,我希望当我单击一个选项卡时会显示一个文本。我已经在类调用的相应 xml 文件中声明了文本。

这里是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");

但它没有显示任何内容。为什么?

【问题讨论】:

    标签: android android-emulator android-widget android-layout textview


    【解决方案1】:

    这是因为您的 FrameLayout 高度设置为 fill_parent,所以它会填满屏幕,将您的 textview 推到窗口之外。

    解决方法是将高度设置为 0dip,然后给它一个 layout_weight="1" 但不要给 textview 或 tabwidget 任何权重属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-11
      • 2020-02-17
      • 2013-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多