自定义列表视图中的图像位置错误

时间:2014-06-14 15:11:56

标签: android listview lazy-loading picasso

我在自定义列表视图上显示图像。正在从URL获取图像。使用Picasso在imageview上设置这些图像。这是它的文档 http://square.github.io/picasso/

但问题是图像位置未正确显示。我搜索了很多,但找不到任何合理的解决方案。 Picasso很适合将远程图像加载到imageview,但我不知道我的采用者有什么问题。这是我的getview代码

public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.items, parent,
                    false);
            holder = new ViewHolder();
            holder.HeadImage = (ImageView) convertView
                    .findViewById(R.id.headingimg);
            String url = headingimage.get(position);
                    Picasso.with(mContext).load(url).into(holder.HeadImage);
            if (position == 0) {
                convertView.setTag(holder);
            }
        } else {
            holder = (ViewHolder) convertView.getTag();

            }

        return convertView;
    } 

任何有关毕加索图书馆或没有毕加索的帮助都会非常感激。谢谢:))

2 个答案:

答案 0 :(得分:0)

试试这个:

public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.items, parent,
                    false);
            holder = new ViewHolder();
            holder.HeadImage = (ImageView) convertView
                    .findViewById(R.id.headingimg);

        }
        holder = (ViewHolder) convertView.getTag();
        String url = headingimage.get(position);
        Picasso.with(mContext).load(url).into(holder.HeadImage);

        return convertView;
    } 

答案 1 :(得分:0)

public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.items, parent,
                false);
        holder = new ViewHolder();
        holder.HeadImage = (ImageView) convertView
                .findViewById(R.id.headingimg);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();

        }String url = headingimage.get(position);
                Picasso.with(mContext).load(url).into(holder.HeadImage);

    return convertView;
}