我有我的 GridViewAdapter,我想用我从 Picasso 加载的内容设置一个 ImageView 。图像已加载,但未显示在 GridView 中,只有当我单击图像时才会全屏显示图像,就像我单击它时所做的那样。每个答案都会被预估。谢谢。
private static LayoutInflater inflater = null;
public GridViewAdapter(Activity a, String[] fpath, String[] fname) {
activity = a;
filepath = fpath;
filename = fname;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return filepath.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.gridview_item, null);
// Locate the TextView in gridview_item.xml
TextView text = (TextView) vi.findViewById(R.id.text);
// Locate the ImageView in gridview_item.xml
image = (ImageView) vi.findViewById(R.id.grid_image);
// Set file name to the TextView followed by the position
Picasso.with(parent.getContext()).load(filepath[position]).placeholder(R.drawable.rtrt).fit().centerCrop().into(image);
// Decode the filepath with BitmapFactory followed by the position
// Set the decoded bitmap into ImageView
// image.setImageBitmap(bmp);
return vi;
}
最佳答案
如果你的图片路径是本地的那么你必须使用文件
File file = new File(filepath[position]);
Picasso.with(activity).load(file).placeholder(R.drawable.rtrt).fit().centerCrop().into(image);
关于android - 如何使用 Picasso 库设置 ImageView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32761010/