@wyouflf 你好,想跟你请教个问题:
我使用BitmapUtils加载列表图片,但是每次刷新列表都出现图片错位的情况,请问是不是要怎么配置BitmapUtils?
另外我是在adapter中使用BitmapUtils。
public class MinShengHotAdapter extends BaseAdapter {
/** The list. */private List<MinShengHot> list;
/** The btm utils. */private BitmapUtils bitmapUtils;
private BitmapDisplayConfig bigPicDisplayConfig;
private LayoutInflater inflater;
/*** Instantiates a new min sheng hot adapter.* * @param context* the context* @param listView* the list view* @param list* the list*/public MinShengHotAdapter(Context context, ListView listView,List<MinShengHot> list) {super();this.list = list;bitmapUtils = new BitmapUtils(context);bitmapUtils.configDefaultLoadFailedImage(R.drawable.small_def);inflater = LayoutInflater.from(context);bigPicDisplayConfig = new BitmapDisplayConfig();// bigPicDisplayConfig.setShowOriginal(true); // 显示原始图片,不压缩, 尽量不要使用,// 图片太大时容易OOM。bigPicDisplayConfig.setBitmapConfig(Bitmap.Config.RGB_565);bigPicDisplayConfig.setBitmapMaxSize(BitmapCommonUtils.getScreenSize(context));listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils,false, true));}
/** (non-Javadoc)* *@see android.widget.Adapter#getCount()*/@Overridepublic int getCount() {// TODO Auto-generated method stubreturn list.size();}
/** (non-Javadoc)* *@see android.widget.Adapter#getItem(int)*/@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn list.get(position);}
/** (non-Javadoc)* *@see android.widget.Adapter#getItemId(int)*/@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}
/** (non-Javadoc)* *@see android.widget.Adapter#getView(int, android.view.View,* android.view.ViewGroup)*/@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubViewHolder viewHolder;if (convertView == null) {viewHolder = new ViewHolder();convertView = inflater.inflate(R.layout.ms_hot_list_item, null);ViewUtils.inject(viewHolder, convertView);convertView.setTag(viewHolder);} else {viewHolder = (ViewHolder) convertView.getTag();}
MinShengHot msh = list.get(position);viewHolder.tvTitle.setText(msh.getTitle());viewHolder.tvContent.setText(msh.getContent_exc());if (!TextUtils.isEmpty(msh.getMinPicName())) {bitmapUtils.display(viewHolder.imageView, RequestConstants.getImageUrl(msh.getMinPicName()),bigPicDisplayConfig);}
return convertView;}
/*** The Class ViewHolder.*/static class ViewHolder {
/** The image view. */@ViewInject(R.id.iv)ImageView imageView;
/** The tv title. */@ViewInject(R.id.tv_title)TextView tvTitle;
/** The tv content. */@ViewInject(R.id.tv_desc)TextView tvContent;}
}
这是我的代码,麻烦帮我看看,谢谢
public class MinShengHotAdapter extends BaseAdapter { /** The list. */ private List<MinShengHot> list; /** The btm utils. */ private BitmapUtils bitmapUtils; private BitmapDisplayConf...
我就没感觉到错位啊。。你先上代码。。
多谢,确实是这个问题
不错
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(6)
public class MinShengHotAdapter extends BaseAdapter {
/** The list. */
private List<MinShengHot> list;
/** The btm utils. */
private BitmapUtils bitmapUtils;
private BitmapDisplayConfig bigPicDisplayConfig;
private LayoutInflater inflater;
/**
* Instantiates a new min sheng hot adapter.
*
* @param context
* the context
* @param listView
* the list view
* @param list
* the list
*/
public MinShengHotAdapter(Context context, ListView listView,
List<MinShengHot> list) {
super();
this.list = list;
bitmapUtils = new BitmapUtils(context);
bitmapUtils.configDefaultLoadFailedImage(R.drawable.small_def);
inflater = LayoutInflater.from(context);
bigPicDisplayConfig = new BitmapDisplayConfig();
// bigPicDisplayConfig.setShowOriginal(true); // 显示原始图片,不压缩, 尽量不要使用,
// 图片太大时容易OOM。
bigPicDisplayConfig.setBitmapConfig(Bitmap.Config.RGB_565);
bigPicDisplayConfig.setBitmapMaxSize(BitmapCommonUtils
.getScreenSize(context));
listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils,
false, true));
}
/*
* (non-Javadoc)
*
*
@see android.widget.Adapter#getCount()
*/
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
/*
* (non-Javadoc)
*
*
@see android.widget.Adapter#getItem(int)
*/
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
/*
* (non-Javadoc)
*
*
@see android.widget.Adapter#getItemId(int)
*/
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
/*
* (non-Javadoc)
*
*
@see android.widget.Adapter#getView(int, android.view.View,
* android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = inflater.inflate(R.layout.ms_hot_list_item, null);
ViewUtils.inject(viewHolder, convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
MinShengHot msh = list.get(position);
viewHolder.tvTitle.setText(msh.getTitle());
viewHolder.tvContent.setText(msh.getContent_exc());
if (!TextUtils.isEmpty(msh.getMinPicName())) {
bitmapUtils.display(viewHolder.imageView, RequestConstants.getImageUrl(msh.getMinPicName()),
bigPicDisplayConfig);
}
return convertView;
}
/**
* The Class ViewHolder.
*/
static class ViewHolder {
/** The image view. */
@ViewInject(R.id.iv)
ImageView imageView;
/** The tv title. */
@ViewInject(R.id.tv_title)
TextView tvTitle;
/** The tv content. */
@ViewInject(R.id.tv_desc)
TextView tvContent;
}
}
这是我的代码,麻烦帮我看看,谢谢
public class MinShengHotAdapter extends BaseAdapter { /** The list. */ private List<MinShengHot> list; /** The btm utils. */ private BitmapUtils bitmapUtils; private BitmapDisplayConf...
我就没感觉到错位啊。。你先上代码。。
多谢,确实是这个问题
不错