android – 毕加索图书馆和GridView图像

前端之家收集整理的这篇文章主要介绍了android – 毕加索图书馆和GridView图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想构建一个使用毕加索库在gridview中显示图像的应用程序.图像由远程服务器检索.我应该创建一个AsyncTask类,还是由Picasso Library本身处理这个类?到目前为止我看过的所有毕加索教程看起来都有些模糊.

谢谢,@H_404_3@

西奥.@H_404_3@

解决方法

使用picasso lib在gridview中加载图像非常简单,as demonstrated here,
class SampleGridViewAdapter extends BaseAdapter {
  private final Context context;
  private final List<String> urls = new ArrayList<String>();

  public SampleGridViewAdapter(Context context) {
    this.context = context;

    // Ensure we get a different ordering of images on each run.
    Collections.addAll(urls,Data.URLS);
    Collections.shuffle(urls);

    // Triple up the list.
    ArrayList<String> copy = new ArrayList<String>(urls);
    urls.addAll(copy);
    urls.addAll(copy);
  }

  @Override public View getView(int position,View convertView,ViewGroup parent) {
    SquaredImageView view = (SquaredImageView) convertView;
    if (view == null) {
      view = new SquaredImageView(context);
      view.setScaleType(CENTER_CROP);
    }

    // Get the image URL for the current position.
    String url = getItem(position);

    // Trigger the download of the URL asynchronously into the image view.
    Picasso.with(context) //
        .load(url) //
        .placeholder(R.drawable.placeholder) //
        .error(R.drawable.error) //
        .fit() //
        .tag(context) //
        .into(view);

    return view;
  }

  @Override public int getCount() {
    return urls.size();
  }

  @Override public String getItem(int position) {
    return urls.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }
}
原文链接:https://www.f2er.com/android/310238.html

猜你在找的Android相关文章