Header未显示RelativeLayout

时间:2013-11-19 17:29:51

标签: android listview relativelayout

我使用ListView来显示一个排名表,但标题没有显示:

这是主要布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dp"
        android:layout_marginTop="1dp"
        android:orientation="horizontal" >

        <!-- Team name -->

        <TextView
            android:id="@+id/team_name"
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:layout_marginLeft="2dp"
            android:ellipsize="marquee"
            android:gravity="center_vertical"
            android:maxLines="1"
            android:text="@string/dash"
            android:textColor="@color/holo"
            android:textIsSelectable="false"
            android:textSize="12sp"
            android:typeface="sans" />

        <!-- Games played -->

        <TextView
            android:id="@+id/games_played"
            android:layout_width="15dp"
            android:layout_height="50dp"
            android:ellipsize="marquee"
            android:gravity="center"
            android:maxLines="1"
            android:text="@string/dash"
            android:textColor="@color/holo"
            android:textIsSelectable="false"
            android:textSize="12sp"
            android:typeface="sans" />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null"
        android:dividerHeight="0px" />

</RelativeLayout>

这是ListView布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="5dip" >

    <!-- Position -->

    <TextView
        android:id="@+id/position"
        android:layout_width="15dp"
        android:layout_height="50dp"
        android:ellipsize="marquee"
        android:gravity="center"
        android:maxLines="1"
        android:textColor="@color/holo"
        android:textIsSelectable="false"
        android:textSize="12sp"
        android:typeface="sans" />

    <!-- Team image -->

    <LinearLayout
        android:id="@+id/team_image_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dip"
        android:layout_toRightOf="@id/position"
        android:background="@drawable/image_bg" >

        <ImageView
            android:id="@+id/team_image"
            android:layout_width="48dip"
            android:layout_height="48dip"
            android:adjustViewBounds="true"
            android:contentDescription="@string/team_image_description"
            android:scaleType="centerCrop" />
    </LinearLayout>

    <!-- Team name -->

    <TextView
        android:id="@+id/team_name"
        android:layout_width="80dp"
        android:layout_height="50dp"
        android:layout_marginLeft="2dp"
        android:layout_toRightOf="@id/team_image_layout"
        android:ellipsize="marquee"
        android:gravity="center_vertical"
        android:maxLines="1"
        android:textColor="@color/holo"
        android:textIsSelectable="false"
        android:textSize="12sp"
        android:typeface="sans" />

    <!-- Games played -->

    <TextView
        android:id="@+id/games_played"
        android:layout_width="15dp"
        android:layout_height="50dp"
        android:layout_toRightOf="@id/team_name"
        android:ellipsize="marquee"
        android:gravity="center"
        android:maxLines="1"
        android:textColor="@color/holo"
        android:textIsSelectable="false"
        android:textSize="12sp"
        android:typeface="sans" />

</RelativeLayout>

显示ListView但不显示标题 我错了什么?

1 个答案:

答案 0 :(得分:0)

你应该将ListView 放在<{1}}下面},你的xml布局应该是这样的:

LinearLayout