毕加索加载重复图像

时间:2014-08-04 10:14:55

标签: java android picasso

我已经搜索过,无法找到任何与此问题相关的内容,我将图片加载到标签页视图中的多个网格视图中。性能很好,但是任何具有大量图像并且需要滚动加载的图像的网格视图都是不正确的,它会将图像加入并将其加载到错误的位置。下面是我用于网格视图的其中一个适配器:

 public class PcAdapter extends BaseAdapter {
    private Context context;

    private Integer[] imageIds = {
            R.drawable.pcserioussam, R.drawable.pc_trinetwo,
            R.drawable.pc_leftfordead, R.drawable.pc_dungeondefenders,
            R.drawable.pc_portaltwo, R.drawable.pc_spaz,
            R.drawable.pc_laracroftattoo, R.drawable.pc_goatsim,
            R.drawable.pc_deadblock, R.drawable.pc_dynasty,
            R.drawable.pc_minecraft, R.drawable.pc_kanelynch,
            R.drawable.pc_toy, R.drawable.pc_awesomenauts,
            R.drawable.pc_bioniccomm, R.drawable.pc_fastandfurious,
            R.drawable.gen_harryone, R.drawable.gen_harrytwo,
            R.drawable.gen_watchmen
    };

    public PcAdapter(Context c) {
        context = c;
    }

    public int getCount() {
        return imageIds.length;
    }

    public Object getItem(int position) {
        return imageIds[position];
    }

    public long getItemId(int position) {
        return 0;
    }

    public View getView(int position, View view, ViewGroup parent) {
        ImageView iview;

        if(view == null){
            iview = new ImageView(context);
            Picasso.with(context).load(imageIds[position]).
                                  placeholder(R.drawable.placeholder).
                                  resize(230, 300).centerInside().into(iview);
        } else {
            iview = (ImageView) view;
        }
        return iview;
    }
}

非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

将你的毕加索代码移出if语句。目前只有在视图为空时才会加载新图像?将它放在return语句之前的if语句的底部。