您的位置:首页 > 其它

RealtiveLayout布局中设置控件layout_above属性的注意事项

2017-07-30 16:39 411 查看
原文地址:http://blog.csdn.net/henan_csdn/article/details/49903629

今天在安卓开发的时候遇到一个小问题,如下,我在一个主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" />
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
android:layout_above="@id/controllayout"
1
1

上面这一句代码一直报异常,说无法找到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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: