2

I'm coding an app with android studio. This is a todolists manager in which you can also add images.

I have a Listview containing items with an ImageView in each. But when there are images to display the listview scrolls really slowly and the app lag.

I saw that I need to do something on a separate thread but how can I do this exactly ?

My app uses MVP and I create the listview with an adapter that extends "BaseAdapter" and uses "setURI" to put the image into the ImageView.

MBek
  • 155
  • 10

4 Answers4

2

Hope this answer will help u Of course u have to use separate thread. U can use imageloader libraries for that according to ur need

Below are libraries link choose which u want to use:

  1. Glide: https://github.com/bumptech/glideenter link description here
  2. Picasso:https://github.com/square/picassoenter link description here

  3. Universal image loader: https://github.com/nostra13/Android-Universal-Image-Loaderenter link description here

Now which to choose I personally recommend glide.if u want to load big size image than go with universal image loader,if u want to go with small images than go with picasso

Hope this answer help u..if u want any other help u can ask for it

Lokesh Desai
  • 2,607
  • 16
  • 28
  • I tried with Picasso and it worked but it's still slow... The pictures take a little more time to load but it still freezes when I scroll :/ – MBek May 21 '17 at 17:47
  • Can u please post ur adapter code here?may be there is another reason for lagging – Lokesh Desai May 21 '17 at 17:51
  • Yes I found it, it was because I wasn't resizing the images with .fit()... Now i do :)... But I'd like to resize them and keeping the proportions, is it possible with picasso ? – MBek May 21 '17 at 17:55
  • Oh, once again, this wasn't hard :p... .centerInside() – MBek May 21 '17 at 17:58
  • I recommend to use resize(width,height) it will reduce image size also – Lokesh Desai May 21 '17 at 18:01
0

Use Picasso to image in a imageview. It uses Automatic memory and disk caching. Hope it will fasten the scrolling.

Just one line of code to load image to ImageView.

Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Pial Kanti
  • 1,550
  • 2
  • 13
  • 26
  • I tried it but it does not display my image... In my adapter : Picasso.with(context).load(Uri.parse(elements.get(position).getImage())).into(iv); (Where "iv" is my image view and element.getImage returns the path) – MBek May 21 '17 at 16:25
  • use getApplicationContext() instead of contex. And check your image path correctly. – Pial Kanti May 21 '17 at 16:28
  • It doesn't work, same with glide... That's weird, because I didn't change anything in the URI, it's the same thing than before. My old code was : "iv.setImageURI(Uri.parse(elements.get(position).getImage()));" and it worked. – MBek May 21 '17 at 16:36
  • what picasso version you are using? @MBek – Pial Kanti May 21 '17 at 16:37
  • 'com.squareup.picasso:picasso:2.5.2' – MBek May 21 '17 at 16:38
  • where are the image files stored? – Pial Kanti May 21 '17 at 16:39
  • These are image from the sdcard (that the user can choose from the galery). – MBek May 21 '17 at 16:40
  • Maybe it's because i use a "Base Adapter" ? – MBek May 21 '17 at 16:49
0

you can use Libraries that optimized to load images like Glide or Picasso. another way is to use a compressed version of images as thumbnail and load the original image when you're showing details of your list item

Amir_P
  • 8,322
  • 5
  • 43
  • 92
0

Use 9 patch images . It will customize the images for every resolution. Sometimes it lags because image resolution is different from your screen resolution.

kunwar97
  • 775
  • 6
  • 14