现象: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"