今天在安卓开发的时候遇到一个小问题,如下,我在一个主RelativeLayout布局中插入了一个listView和一个子RelativeLayout,我想让listView显示在子RelativeLayout上方,同时让占据上方的整个窗口,在按照下面的这种写法写的时候,
<ListView
android:id="@+id/list_files"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/controllayout"
android:layout_alignParentTop="true" >
</ListView>
<RelativeLayout
android:id="@+id/controllayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
android:layout_above="@id/controllayout"
上面这一句代码一直报异常,说无法找到controllayout这个资源。
后经网络搜索后,得知,如果要通过这种方式设置A在B之上的效果的话,那么B一定要先定义,并且要写在A前面,所以解决方法就出来了,把子RealtiveLayout定义在listView前面就ok(不知道什么原理,求高人解答~)
<RelativeLayout
android:id="@+id/controllayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<ListView
android:id="@+id/list_files"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/controllayout"
android:layout_alignParentTop="true" >
</ListView>