核心代码:
package android88.app.listview.demo.adapter;
import java.util.List;
import net.tsz.afinal.FinalBitmap;
import android.R.integer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android88.app.listview.demo.R;
public class Win8ListAdapter extends BaseAdapter {
List<String> _ImgsURL;
int _ItemCountNumber; // 列表总条数
int _AItemShowImgNumber = 3; // 列表每条显示图片数
Context _Context;
FinalBitmap _FinalBitmap;
public Win8ListAdapter(Context context, List<String> imgsURL) {
_Context = context;
_ImgsURL = imgsURL;
if (imgsURL.size() % _AItemShowImgNumber == 0) {
_ItemCountNumber = imgsURL.size() / _AItemShowImgNumber;
} else {
_ItemCountNumber = imgsURL.size() / _AItemShowImgNumber + 1;
}
_FinalBitmap = FinalBitmap.create(_Context);// 初始化FinalBitmap模块
}
@Override
public int getCount() {
return _ItemCountNumber;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
static class ViewHold {
ImageView subImageView1;
ImageView subImageView2;
ImageView subImageView3;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHold _ViewHold = new ViewHold();
if (position % 2 == 0) {
convertView = LayoutInflater.from(_Context).inflate(
R.layout.item_one, null);
} else {
convertView = LayoutInflater.from(_Context).inflate(
R.layout.item_two, null);
}
_ViewHold.subImageView1 = (ImageView) convertView
.findViewById(R.id.subItem1);
_ViewHold.subImageView2 = (ImageView) convertView
.findViewById(R.id.subItem2);
_ViewHold.subImageView3 = (ImageView) convertView
.findViewById(R.id.subItem3);
for (int i = 0; i < _AItemShowImgNumber; i++) {
int index = position * _AItemShowImgNumber + i;
if (index >= _ImgsURL.size()) {
break;
} else {
if (i == 0) {
_ViewHold.subImageView1.setVisibility(View.VISIBLE);
_FinalBitmap.display(_ViewHold.subImageView1, _ImgsURL.get(index));
} else if (i == 1) {
_ViewHold.subImageView2.setVisibility(View.VISIBLE);
_FinalBitmap.display(_ViewHold.subImageView2, _ImgsURL.get(index));
} else if (i == 2) {
_ViewHold.subImageView3.setVisibility(View.VISIBLE);
_FinalBitmap.display(_ViewHold.subImageView3, _ImgsURL.get(index));
}
}
}
return convertView;
}
}
代码下载地址:
http://download.csdn.net/detail/java886o/6201613
代码运行效果: