我在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>
答案 0 :(得分:0)
检查此链接
Difference between "@id/" and "@+id/" in Android
和
在listView
android:layout_below="@id/allclassess_institutename"
由此
android:layout_below="@+id/allclassess_institutename"
修改强>
将TextView
与parentTop
对齐并尝试..
<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>