listView原理记录

转载自:[url]https://blog.csdn.net/guolin_blog/article/details/44996879[/url]


-listView和adapter是为了解耦,一个负责视图,一个负责数据绑定
-listView通过RecycleBin来不断填充可见item,以及循环废弃item。
-AbsListView的onlayout来实现绘制item。ListView的onlayout根据dataChanged是否数据有更新,进行对可见item的填充。
-填充可见item时,

View obtainView(int position, boolean[] isScrap) {
isScrap[0] = false;
View scrapView;
scrapView = mRecycler.getScrapView(position);
View child;
if (scrapView != null) {
child = mAdapter.getView(position, scrapView, this);
if (child != scrapView) {
mRecycler.addScrapView(scrapView);
if (mCacheColorHint != 0) {
child.setDrawingCacheBackgroundColor(mCacheColorHint);
}
} else {
isScrap[0] = true;
dispatchFinishTemporaryDetach(child);
}
} else {
child = mAdapter.getView(position, null, this);
if (mCacheColorHint != 0) {
child.setDrawingCacheBackgroundColor(mCacheColorHint);
}
}
return child;
}

会跟根据是否有废弃的item,来传给adapter是否可有convertView利用

-之后每次onlayout时,detachAllViewsFromParent将所有item解绑,填充好可见item后,再绑定


[img]http://dl2.iteye.com/upload/attachment/0130/2974/ae862947-5507-3f41-985f-1b20486cb207.png[/img]

你可能感兴趣的:(android)