【问题标题】:Text at the top of Android Tab host layoutAndroid Tab 主机布局顶部的文本
【发布时间】:2011-04-05 07:56:40
【问题描述】:

我按照this 的示例进行了操作。

现在我想显示“欢迎!!!” Tabhost 布局中选项卡上方的文本,如图中所示

这是我当前的布局文件。但它不显示欢迎消息。

<?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:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="top"
            android:layout_gravity="top"
            android:padding="5dp">
            <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/cc_welcome" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="Welcome"
                android:gravity="top" android:padding="50dp" android:textColor="#ffffff"/>
        </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="bottom"
        android:layout_gravity="bottom"
        android:paddingTop="50dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_alignParentTop="true"
            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" />
        </LinearLayout>

</TabHost>

【问题讨论】:

    标签: android android-layout android-tabhost


    【解决方案1】:

    我已经编辑了 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">
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <RelativeLayout
                android:id="@+id/welcome"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/cc_welcome" 
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" 
                    android:text="Welcome"
                    android:layout_centerInParent="true"
                    android:textColor="#ffffff"/>
            </RelativeLayout>
            <RelativeLayout
                android:layout_below="@id/welcome"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_alignParentTop="true"
                    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:layout_below="@android:id/tabs"/>
            </RelativeLayout>
        </RelativeLayout>
    </TabHost>
    

    我已经更新了代码。你现在可以试试吗?

    您将更好地了解线性和相对布局here

    【讨论】:

      猜你喜欢
      • 2014-01-24
      • 2016-08-29
      • 1970-01-01
      • 2011-06-30
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多