Android中一个Activity两个ListView的显示错误问题

来源:互联网 发布:win7如何设置网络类型 编辑:程序博客网 时间:2024/05/01 15:37

我想要在一个Activity中显示两个列表控件(Activity绑定的layout中有两个ListView组件)如:

<?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"    android:orientation="vertical"     android:background="@drawable/bg">    <!-- start -->    <ListView         android:id="@+id/lstfirst"        android:layout_width="fill_parent"        android:layout_height="fill_parent“/>    <!-- end -->    <ListView         android:id="@+id/lstReplys"        android:layout_width="fill_parent"        android:layout_height="fill_parent"/></RelativeLayout>

然后对每个ListView组件从服务器端获取数据并进行数据绑定之后,但是只能显示第一个ListView组件的内容,即使第二个ListView组件的高度高于第一个ListView也只显示第一个ListView组件的内容,就好像系统忽略了第二个ListView组件。

解决方法:在俩个ListView组件之间添加margin-top属性:

<ListView         android:id="@+id/lstfirst"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_marginTop="50px"/>    <!-- end -->    <ListView         android:id="@+id/lstReplys"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_marginTop="160px"/>

如android:layout_marginTop=”50px”之后就可以显示出俩个ListView组件内容了

还有一个问题:就是到底是多少px合适呢?试过其它数值但都有一个问题就是2个ListView不能很好的融合,也就是2个组件之前缺少一个灰色横线,但如果用50px的话,2个ListView之间就会出现一个灰色横线,这样就会看起来仿佛是一个ListView的效果(这也正是楼主想要的效果)

0 0
原创粉丝点击