ListView项重叠TextView

时间:2015-02-03 09:35:44

标签: android android-layout listview

我在ListView中实施了Activity。我有布局问题。我在TextView中有Activity,然后在下面,我需要显示ListView项。两者都正确填充,但第一个ListView项与TextView布局重叠,因此TextView文本和第一个ListView项文本显示在同一行中。我在下面放置布局文本。请告诉我我缺少的布局属性,并应该用来纠正问题。

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.rrd.school.project.AllClasses" >

    <TextView 
        android:id="@+id/allclassess_institutename"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:visibility="visible"
        android:textSize="10pt"
        android:textColor="#0404B4"
        android:background="#DF3A01"
        />
    <ListView 
        android:id="@+id/classlistview"
        android:layout_below="@+id/allclassess_institutename"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        />
</RelativeLayout>

listviewitem.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.rrd.school.project.ClassListItme" >

    <TextView
        android:id="@+id/classid"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:visibility="gone"
        />
    <TextView 
        android:id="@+id/classname"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_centerHorizontal="true"
        android:visibility="visible"
        android:textSize="8pt"
        android:textColor="#0404B4"
        />

</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

检查此链接

Difference between "@id/" and "@+id/" in Android

listView

中替换此行
android:layout_below="@id/allclassess_institutename"

由此

android:layout_below="@+id/allclassess_institutename"

修改

TextViewparentTop对齐并尝试..

<TextView
  android:id="@+id/allclassess_institutename"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#DF3A01"
  android:layout_alignParentTop="true"
  android:gravity="center"
  android:textColor="#0404B4"
  android:textSize="10pt"
  android:visibility="visible" />

<ListView
  android:id="@+id/classlistview"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@+id/allclassess_institutename"
  android:fillViewport="true" />

答案 1 :(得分:0)

RelativeLayout根据视图之间的“关系”(得到它,相对关系)安排视图。这是一个复杂但非常强大的ViewGroup。但是如果您只需要一个在另一个之下,您可以轻松地替换为LinearLayout,如下所示:

<LinearLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.rrd.school.project.AllClasses" >

<TextView 
    android:id="@+id/allclassess_institutename"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="10pt"
    android:textColor="#0404B4"
    android:background="#DF3A01" />
<ListView 
    android:id="@+id/classlistview"
    android:layout_height="match_parent"
    android:layout_width="match_parent" />
</LinearLayout>