質問

I want to make an application which loads image urls from my site (returned in a JSONArray) and then display the images in a gridview (the photos are also online, so needs to be loaded).

The problem is that I am confused which library is easier to use and has better performance?

Android Query or Android Universal Image Loader (UIL) ?

役に立ちましたか?

解決 5

Android Universal Image Loader works like a champ.

It's very easy to use here is an example

But, basically this is the way to use it with a GridView:

After the expected imports, you should:

protected AbsListView list;

protected ImageLoader loader = ImageLoader.getInstance();

private String query;

final Context context = this;

private ItemAdapter adapter;

private DisplayImageOptions op;

@Override
 public void onCreate(Bundle savedInstanceState) {

 op = new DisplayImageOptions.Builder()
         .displayer(new RoundedBitmapDisplayer(20))
         .build();

 list = (GridView) findViewById(R.id.gridViewSearch);
 adapter = new ItemAdapter(images);
 list.setAdapter(adapter);
 list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

     @Override
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
       // Do whatever you need to do after clicking an image.
     }
 });
}

And, of course you need the adapter:

class ItemAdapter extends BaseAdapter {

 private String[] imagesA;

 public ItemAdapter(String [] Images){
     this.imagesA = Images;
 }

 public void setData(String [] Images){
     this.imagesA = Images;
 }

 private class ViewHolder {
     public ImageView image;
 }

 @Override
 public int getCount() {
     return imagesA.length;
 }

 @Override
 public Object getItem(int position) {
     return position;
 }

 @Override
 public long getItemId(int position) {
     return position;
 }

 @Override
 public View getView(final int position, View convertView, ViewGroup parent) {
     View v = convertView;
     v = getLayoutInflater().inflate(R.layout.image_in_gridview_layout, parent, false);
     final ProgressBar spinner = (ProgressBar) v.findViewById(R.id.loading);
     final ViewHolder holder = new ViewHolder();
     holder.image = (ImageView) v.findViewById(R.id.grid_item_image);
     v.setTag(holder);

     loader.displayImage(imagesA[position], holder.image, op, new SimpleImageLoadingListener() {
         @Override
         public void onLoadingStarted(String imageUri, View view) {
             spinner.setVisibility(View.VISIBLE);
         }

         @Override
         public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
             spinner.setVisibility(View.GONE);
         }

         @Override
         public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
             spinner.setVisibility(View.GONE);
         }
     });

     return v;
 }

他のヒント

Android Universal Image Loader is the most popular one out there currently. Highly customizable, tuto.

AQuery; like jquery, but for Android? I guess it's nice, if you're into that sort of thing. Don't use this one though; it craps on the UI thread or something. Loading a bunch of images on my Nexus 4 in a listview made it seem like I was back on my HTC G1 all over again. Major stuttering, tuto.

More:

Picasso has the nicest image API. I am going to steal their currying API style for my future/current stuff. Picasso is also noticeably the slowest. Especially on 3g vs wifi. Probably due to their custom okhttp client, tuto.

UrlImageViewHelper + AndroidAsync is the fastest. Playing with these other two great libraries have really highlighted that the image API is quite dated, however.

Volley is slick; I really enjoy their pluggable backend transports, and may end up dropping AndroidAsync in there. The request priority and cancellation management is great, Google I/O 2013 presentation, tuto.

I recommend for you to make choice between Volley and Picasso

You can use Ion https://github.com/koush/ion or Picasso by square http://square.github.io/picasso/ ,both are great !

Picasso (By Square) is very helpful and easy to use: http://square.github.io/picasso/

You should look into it.

For me: Picasso is the way to go!

Why?

  • Very fast
  • Stable
  • Easy to use
  • Mostly one line of code

I used to use Universal ImageLoader 1.9.0 (UIL), till I had to use a ListView with an OnScrollListener, where the next 10 items where downloaded and the scrolling became not fluently enough with UIL while FAST-scrolling back and forth with, for example, 50 items loaded. To accomplish a smooth scrolling, I've tried different configurations and options in UIL(did not help, except the delay option a bit) and I've tried AQuery(fast, but on scroll images vanished and appeared again even with a placeholder set) and UrlImageViewHelper(fast, but I could not set a drawable as a placeholder in case of "No Network Connection"), so I ended up with Picasso (the fastest from those four I've tested, hence a smooth scrolling) :)

But I have to give a big compliment to NOSTRA13 (creator of UIL) anyway because of:

  • Clean and easy-to-follow documentation
  • Easy to use
  • Many options
  • Stable
  • Reliable support

Testing Environment:
Android HTC Desire X and a very weak Wifi-Connection.

EDIT:
I'm taking it back that other image-load-libs are faster: UIL is now for me the champ too! :)
I had always a scroll-lag with UIL on first load of the images and I knew it has something to do with the scrolling, so I was searching the net for more info till I found this beautiful post:
ListView scrolling using UniversalImageDownloader not smooth
So I set the PauseOnScrollListener and see there, problem solved!
Hence: UIL is number 1!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top