Reputation: 446
I have a Listview with items which contain ImageView. Unfortunately I am getting an OME if I load more than 20 items. I am using the Glide library to load items into the ImageViews. My question is if there is another way to handle this than loading smaller images from my server?
Looking forward to nice answers!
EDIT:
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"); ...
This is my Code of the getView Method. I could get the bitmap from the Glide LIbery but how could i scall it down than and cache it efficiently?
Upvotes: 0
Views: 2185
Reputation: 499
Please post your adapter code so we can see where exactly is your problem.
Over the top of my head there are a few things you could do to make the loading and handling of bitmaps perform better, first of all i would suggest switching bitmap format to RGB_565 instead of the default ARGB_8888, it would take 50% less memory! In addition i would try and cache images on memory since the adapter would call the loading function each time it request getView(unless you have an isLoaded flag or something), and last i would load the bitmap at the exact size of the ImageView so it doesn't take anymore pixels than needed.
Read this for deeper understanding of bitmap handling: http://developer.android.com/training/displaying-bitmaps/index.html
Upvotes: 2