我有一個包含ImageView的項目的Listview。不幸的是,如果我加載超過20個項目,我正在獲得OME。我正在使用Glide庫將項目加載到ImageViews中。我的問題是,如果有另一種方法來處理這個問題,比從我的服務器加載較小的圖像?Android - 內存不足Glide Library的異常
期待好的答案!
編輯:
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.post_list_item, parent, false);
back = (ImageView) rowView.findViewById(R.id.imageView3);
filter = (ImageView) rowView.findViewById(R.id.imageView2);
final RelativeLayout deleteContainer = (RelativeLayout) rowView.findViewById(R.id.deleteContainer);
final ImageView deletAdd = (ImageView) rowView.findViewById(R.id.imageView1);
deletAdd.setScaleX(0.5f);
deletAdd.setScaleY(0.5f);
View backDelete = (View) rowView.findViewById(R.id.View1);
Glide.with(context).load(postList.get(position).getThumb()).diskCacheStrategy(DiskCacheStrategy.RESULT)
.override(AppData.width, AppData.height/6).centerCrop().into(back);
TextView title = (TextView) rowView.findViewById(R.id.textView1);
title.setTypeface(AppData.glogooregular);
if (postList.get(position).getThumb() == null) {
filter.setVisibility(View.GONE);
title.setBackgroundColor(Color.parseColor("#FFFFFF"));
title.setTextColor(Color.parseColor("#000000"));
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) title.getLayoutParams();
params.setMargins(0, 0, 0, 0);
title.setLayoutParams(params);
} else {
title.getLayoutParams().height = AppData.height/6;
}
TextView date = (TextView) rowView.findViewById(R.id.textView2);
TextView comments = (TextView) rowView.findViewById(R.id.textView3);
title.setText(postList.get(position).getTitle());
SimpleDateFormat month_date = new SimpleDateFormat("MMM");
Calendar cal = DateToCalendar(new Date(Long.parseLong(postList.get(position).getTime()) * 1000));
String month_name = month_date.format(new Date(cal.getTimeInMillis()));
date.setText(cal.get(Calendar.DAY_OF_MONTH) + "." + month_name + " - " + cal.get(Calendar.HOUR_OF_DAY) + ":"
+ cal.get(Calendar.MINUTE) + " Uhr"); ...
這是我的getView法碼。我可以從Glide LIbery獲取位圖,但我怎麼能縮小它並高效地緩存呢?
謝謝您的快速響應和我去嘗試了這一點,我回來算賬! –