您的位置:首页 > 移动开发 > Android开发

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

2015-07-01 20:26 337 查看
我想要在一个Activity中显示两个列表控件(Activity绑定的layout中有两个ListView组件)如:

[code]<?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属性:

[code]<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的效果(这也正是楼主想要的效果)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: