Android Tab主机布局顶部的文本

Mit*_*ran 3 android android-layout android-tabhost

我按照这个例子进行了操作.

现在我要展示一个'欢迎!!!' 正好在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>
Run Code Online (Sandbox Code Playgroud)

Dij*_*vid 6

我编辑了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>
Run Code Online (Sandbox Code Playgroud)

我已经更新了代码.你能来试试吗?

您将在此处更好地了解线性和相对布局