/**
* Subclasses should NOT override this method but {@link #layoutChildren()}
* instead.
*/
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
mInLayout = true;
if (changed) {
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
getChildAt(i).forceLayout();
}
mRecycler.markChildrenDirty();
}
layoutChildren();
mInLayout = false;
}
/**
* Fills the list from pos down to the end of the list view.
*
* @param pos The first position to put in the list
*
* @param nextTop The location where the top of the item associated with pos
* should be drawn
*
* @return The view that is currently selected, if it happens to be in the
* range that we draw.
*
* @param pos:列表中的一个绘制的Item在Adapter数据源中对应的位置
* @param nextTop:表示当前绘制的Item在ListView中的实际位置..
*/
private View fillDown(int pos, int nextTop) {
View selectedView = null;
/**
* end用来判断Item是否已经将ListView填充满
*/
int end = (getBottom() - getTop()) - mListPadding.bottom;
while (nextTop < end && pos < mItemCount) {
/**
* nextTop < end确保了我们只要将新增的子View能够覆盖ListView的界面就可以了
*pos < mItemCount确保了我们新增的子View在Adapter中都有对应的数据源item
*/
// is this the selected item?
boolean selected = pos == mSelectedPosition;
View child = makeAndAddView(pos, nextTop, true, mListPadding.left, selected);
/**
*将最新child的bottom值作为下一个child的top值,存储在nextTop中
*/
nextTop = child.getBottom() + mDividerHeight;
if (selected) {
selectedView = child;
}
pos++;
}
return selectedView;
}
private View makeAndAddView(int position, int y, boolean flow, int childrenLeft,
boolean selected) {
View child;
//判断数据源是否发生了变化.
if (!mDataChanged) {
// Try to use an exsiting view for this position
//如果mActivityView[]数组中存在可以直接复用的View,那么直接获取,然后重新布局.
child = mRecycler.getActiveView(position);
if (child != null) {
// Found it -- we're using an existing child
// This just needs to be positioned
setupChild(child, position, y, flow, childrenLeft, selected, true);
return child;
}
}
// Make a new view for this position, or convert an unused view if possible
/**
*如果mActivityView[]数组中没有可用的View,那么尝试从mScrapView数组中读取.然后重新布局.
*如果可以从mScrapView数组中可以获取到,那么直接返回调用mAdapter.getView(position,scrapView,this);
*如果获取不到那么执行mAdapter.getView(position,null,this)方法.
*/
child = obtainView(position, mIsScrap);
// This needs to be positioned and measured
setupChild(child, position, y, flow, childrenLeft, selected, mIsScrap[0]);
return child;
}
if (scrapView != null) {
child = mAdapter.getView(position, scrapView, this);
}
else {
child = mAdapter.getView(position, null, this);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = View.inflate(context, R.layout.list_item_layout, null);
}
return convertView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
ListViewItem itemData = items.get(position);
if(convertView == null){
convertView = View.inflate(context, R.layout.list_item_layout, null);
holder = new ViewHolder();
holder.userImg = (ImageView) convertView.findViewById(R.id.user_header_img);
holder.userName = (TextView) convertView.findViewById(R.id.user_name);
holder.userComment = (TextView) convertView.findViewById(R.id.user_coomment);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.userImg.setImageResource(itemData.getUserImg());
holder.userName.setText(itemData.getUserName());
holder.userComment.setText(itemData.getUserComment());
return convertView;
}
static class ViewHolder{
ImageView userImg;
TextView userName;
TextView userComment;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有