android listview滚动中没有平滑功能,就像whatsapp新聊天联系人列表一样
我的listview有1个图像视图和2个文本视图,但当我向下滚动它时,它不能平稳工作,所以我该怎么办 这是我的密码android listview滚动中没有平滑功能,就像whatsapp新聊天联系人列表一样,android,listview,scrollview,baseadapter,custom-adapter,Android,Listview,Scrollview,Baseadapter,Custom Adapter,我的listview有1个图像视图和2个文本视图,但当我向下滚动它时,它不能平稳工作,所以我该怎么办 这是我的密码 class ReceiptAdapter extends BaseAdapter { ArrayList<GetterSetter> receiptlist; private LayoutInflater inflater; // private int[] colors = new int[] { Color.parseColor("#C8
class ReceiptAdapter extends BaseAdapter {
ArrayList<GetterSetter> receiptlist;
private LayoutInflater inflater;
// private int[] colors = new int[] { Color.parseColor("#C8A6DA"),
// Color.parseColor("#F6F4AB"), Color.parseColor("#A2C3D0"),
// Color.parseColor("#F1B4A1") };
private int[] colors = new int[] { Color.parseColor("#2280aee3"),
Color.parseColor("#22888888") };
public ReceiptAdapter(Context context,
ArrayList<GetterSetter> receiptlist) {
// TODO Auto-generated method stub
this.receiptlist = receiptlist;
// inflater = LayoutInflater.from(context);
// inflater = LayoutInflater.from(context.getApplicationContext());
inflater = (LayoutInflater) getActivity().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return receiptlist.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null) {
// convertView = inflater.inflate(R.layout.custom_list, null);
convertView = inflater.inflate(R.layout.custom_list, parent,
false);
// if (position % 2 == 1) {
// convertView.setBackgroundColor(Color.BLUE);
// } else {
// convertView.setBackgroundColor(Color.CYAN);
// }
int colorPos = position % colors.length;
convertView.setBackgroundColor(colors[colorPos]);
holder = new ViewHolder();
holder.Title = (TextView) convertView.findViewById(R.id.name);
holder.Total = (TextView) convertView.findViewById(R.id.total);
holder.Img = (ImageView) convertView
.findViewById(R.id.profile_image);
Animation animation = null;
animation = AnimationUtils.loadAnimation(getActivity(),
R.anim.wave);
animation.setDuration(200);
convertView.startAnimation(animation);
animation = null;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.Title.setText(receiptlist.get(position).getTitle());
holder.Total.setText(receiptlist.get(position).getTotal());
String path = receiptlist.get(position).getImg();
File fileImg = new File(path);
Bitmap bitmap = null;
if (fileImg.exists()) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 7;
bitmap = BitmapFactory.decodeFile(fileImg.getAbsolutePath(),
options);
// bitmap = BitmapFactory.decodeFile(fileImg.getAbsolutePath());
holder.Img.setImageBitmap(bitmap);
}
else
{
Bitmap icon = BitmapFactory.decodeResource(getActivity().getResources(),
R.drawable.no_image);
holder.Img.setImageBitmap(icon);
}
holder.Img.setScaleType(ScaleType.CENTER_CROP);
return convertView;
}
class ViewHolder {
TextView Title;
TextView Total;
ImageView Img;
}
}
所以,我的问题是我哪里做错了
就像whatsapp中的联系人列表一样,它加载图像并在图像视图中显示,我从sd卡获取图像并在图像视图中显示,那么为什么滚动视图不能顺利工作呢
我应该为此实施什么
我也在stackoverflow上搜索了很多代码,但是我发现了其他人的错误,但是没有得到任何好的可行的解决方案,所以如果有人能在这方面帮助我,我将不胜感激。谢谢你的语气 您需要在后台加载图像,而不是在主线程中。为此,您应该使用处理该问题的库。最好的图书馆是: 毕加索 通用图像下载 在实现其中一个库之后,您应该使用它在后台加载图像,该库将图像缓存在内存中,并处理其他选项,如错误dowwload的占位符、应用动画显示图像等
对不起,我的英语不好或者你可以使用截击-这是谷歌的标准REST库,也可以加载图像。这些文档是对位图使用延迟加载谢谢你@PiotrGolinski我会试试那一个..你好@encastellano非常感谢你,让我试试这一个,你的英语很好。。别担心谢谢@Dogosh:让我试试这个!
ReceiptAdapter adapter = new ReceiptAdapter(getActivity(),
recList);
setListAdapter(adapter);