gpt4 book ai didi

java - picasso 加载重复图像

转载 作者:行者123 更新时间:2023-11-30 02:45:28 25 4
gpt4 key购买 nike

我已经搜索过但找不到与我遇到的这个问题有任何关系,我将图像加载到多个 GridView 中,每个 GridView 都在一个选项卡式页面 View 中。性能很好,但是任何包含大量图像并需要滚动加载的图像的 GridView 都是不正确的,它会复制图像并将它们加载到错误的位置。下面是我用于 GridView 的适配器之一:

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

如有任何帮助,我们将不胜感激

最佳答案

将您的 picasso 代码移出 if 语句。目前它只会在 View 为空时加载新图像?将它放在 if 语句的底部,就在 return 语句之前。

关于java - picasso 加载重复图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25116411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com