您的位置:首页 > 其它

BaseAdapter的getView中经常出现position=0的情况

2014-09-04 12:18 295 查看
ListView的布局会影响getView的调用,当我的布局为

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
	<ListView
	    android:id="@+id/myList"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"/>
</LinearLayout>

position=0调用了两次,而且我在geiview中没有生成足够数量的view时,convertView居然也返回了非空的值给我,正常是有view被回收时才会有非空的convertView返回

根据博客:http://blog.csdn.net/junjieking/article/details/7490602

我把布局改成了:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="fill_parent">
	<ListView
	    android:id="@+id/myList"
		android:layout_width="match_parent"
		android:layout_height="match_parent"/>
</LinearLayout>


就正常了,开始时都是由geiView生成新的view,滚动列表有view被回收后converView传递缓存的view给geiView,但是还不知道这原因是为什么,有了解的朋友请告诉一下我,谢谢哈。

在这里找到比较好的解释:http://www.cnblogs.com/linjzong/p/3494090.html



可以看到如果高度或者宽度是 UNSPECIFIED的话,listview就会调用obtainView(0, mIsScrap),其中0就是传递给getView的position
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: