ListView,GridView的Adapter中的getView执行异常

现象:ListView,GridView的Adapter中的getView执行异常,position = 0 会执行很多次,这样有诸多弊病:

1、效率低,ListView 的填充本省就是比较华时间的

2、给其他操作带来巨大的麻烦:比如:Adapter中可能要执行图片异步加载,每个Item都要执行,会导致多添加了异步加载任务,图片加载不出来,图片错位。我碰到最大的问题就是刷新Item中的下载进度条,这个让我几乎崩溃了。最后绕过问题,但是,后期问题也爆发了。我更新进度条是:刷新所有Item,效率不说,图片还会乱跳.......还有,item中的按钮会变得很不灵敏、、、、

现在貌似找到问题了,但是LLL说过:程序中永远有你想不到的地方!所以,不敢托大认为就解决了。看来。listView的源代码真的是需要仔细看看!!

上图:

正常的情况:

 <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/btn_task"
            android:layout_marginRight="6dp"
            android:cacheColorHint="@android:color/transparent"
            android:divider="#123" />




异常的情况:

 <ListView
            android:id="@+id/listview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn_task"
            android:layout_marginRight="6dp"
            android:cacheColorHint="@android:color/transparent"
            android:divider="#123" />



其他:固定宽高,也是异常情况,不是我们想要的

<ListView
            android:id="@+id/listview"
            android:layout_width="600dp"
            android:layout_height="50dp"
            android:layout_below="@id/btn_task"
            android:layout_marginRight="6dp"
            android:cacheColorHint="@android:color/transparent"
            android:divider="#123" />


总结:ListView在整个 layout 中,写成 fill_parent(两个都要这么写),千万不要写成 wrap_content,

 android:layout_width="fill_parent"
 android:layout_height="fill_parent"


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值