android - 如何使用 Picasso 库设置 ImageView ?

标签 android picasso

我有我的 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/

相关文章:

android - picasso :2个 fragment 之间的共享元素过渡

android - 在 picasso 中使用回调获取图像?

android - Nexus one 未显示在 DDMS 问题中

android - 在 ExpandableListView 的 Default GroupIndicator 上添加 onClickListener

java - JPEG 文件中的 EXIF 数据

android - 我如何响应 Android MapView 上的点击,但忽略双指缩放?

android - 无法使用 picasso 加载图像

java - Android picasso : Method call should happen from the main thread

android - 自定义 ImageView 类不适用于 picasso 图像下载库

android - Firebase API 初始化失败 Android+Firebase