布局文件代码如下:
layout_above没有起作用,listview把textview覆盖了
<?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="match_parent" >
<ListView
android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/listView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:text="TextView" />
</RelativeLayout>
但是在listview中添加属性android:layout_below="@+id/textView1"
就没有问题
Because
wrap_content
对ListView
是不起效的,还是会撑满整个屏幕高度,先写的ListView
,屏幕已经无空间了,再加TextView
自然是看不见的(而不是覆盖)。还有,严谨的相对id写法应该是android:layout_below="@id/textView1"
You can do this:
The view tree draws views from outside to inside and from top to bottom. The measurement and layout methods of the former will affect the latter, so the dependencies should be placed in the previous view to constrain them.