哪个Android图片库用于在线照片加载

我想创建一个从我的站点加载图像URL的应用程序(在JSONArray中返回),然后在gridview中显示图像(照片也在线,因此需要加载).

问题是我很困惑哪个库更容易使用并且具有更好的性能?

Android查询或Android通用图像加载器(UIL)?

解决方法:

Android Universal Image Loader就像一个冠军.

它很容易使用here就是一个例子

但是,基本上这是将它与GridView一起使用的方法:

在预期的进口之后,你应该:

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.
     }
 });
}

当然,你需要适配器:

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 onl oadingStarted(String imageUri, View view) {
             spinner.setVisibility(View.VISIBLE);
         }

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

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

     return v;
 }
上一篇:OpenAPI-Swagger3-介绍使用


下一篇:【译】ASP.NET Core Web API文档(Swagger/OpenAPI)