Droidfu WebImageView 和 GridView 问题

发布于 2024-11-09 16:58:22 字数 1961 浏览 1 评论 0原文

我在 GridView 中使用 Droidfu 的小部件 WebImageView 来创建图库。图像与 WebImageView 异步下载并缓存。

问题是当网格滚动到 id 时,它并不总是显示图像(而是显示默认错误 img)。就像 getView 正在销毁它并且无法每次正确地回收它一样。

这是我的 GridAdapter

公共类 GalleryAdapter 扩展 BaseAdapter {

    private Context mContext;

    public GalleryAdapter(Context c) {
        // TODO Auto-generated constructor stub
        mContext = c;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return theList.getItemCount();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return theList.getItem(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        final GalleryItem galeryItem = theList.getItem(position);

        if (convertView == null) {
            convertView = (View) getLayoutInflater().inflate(R.layout.gallery_item, parent, false);

        }

        WebImageView imageView = (WebImageView) convertView.findViewById(R.id.webimage);

        if (!galeryItem.getMain_image().trim().equalsIgnoreCase("")) {  

            imageView.setScaleType(ScaleType.CENTER_CROP);
            imageView.setAdjustBounds(true);
            imageView.reset();
            imageView.setImageUrl(galeryItem.getMain_image().trim());
            imageView.setNoImageDrawable(R.drawable.heading_img_bg);
            imageView.loadImage();
        }

        TextView heading = (TextView) convertView.findViewById(R.id.gallery_heading);
        heading.setText(galeryItem.getHeading());

        TextView img_num = (TextView) convertView.findViewById(R.id.gallery_img_num);
        img_num.setText(Integer.toString(galeryItem.getImage_num()));   

        return convertView;
    }

}

Im using Droidfu's widget WebImageView inside GridView to create gallery. Image is beeing async downloaded with WebImageView and cached.

The problem is that id doesn't always show the image (it shows default error img instead) when grid scrolls to it. It's like getView is destroying it and not being able to recycle it every time properly.

This is my GridAdapter

public class GalleryAdapter extends BaseAdapter {

    private Context mContext;

    public GalleryAdapter(Context c) {
        // TODO Auto-generated constructor stub
        mContext = c;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return theList.getItemCount();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return theList.getItem(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        final GalleryItem galeryItem = theList.getItem(position);

        if (convertView == null) {
            convertView = (View) getLayoutInflater().inflate(R.layout.gallery_item, parent, false);

        }

        WebImageView imageView = (WebImageView) convertView.findViewById(R.id.webimage);

        if (!galeryItem.getMain_image().trim().equalsIgnoreCase("")) {  

            imageView.setScaleType(ScaleType.CENTER_CROP);
            imageView.setAdjustBounds(true);
            imageView.reset();
            imageView.setImageUrl(galeryItem.getMain_image().trim());
            imageView.setNoImageDrawable(R.drawable.heading_img_bg);
            imageView.loadImage();
        }

        TextView heading = (TextView) convertView.findViewById(R.id.gallery_heading);
        heading.setText(galeryItem.getHeading());

        TextView img_num = (TextView) convertView.findViewById(R.id.gallery_img_num);
        img_num.setText(Integer.toString(galeryItem.getImage_num()));   

        return convertView;
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅忆流年 2024-11-16 16:58:22

根据 this,Droid-Fu 的开发将停止,并且将“更名为”Ignition

Ignition 有一个类似的类,称为 RemoteImageView。用法基本相同,但似乎他们对后端进行了一些修改。我用 ListView 尝试过,但出现了永远加载的问题。为我工作(尽管它引入了一些其他问题)。

您可以尝试一下,看看您的问题是否已得到解决。

According to this, development on Droid-Fu is going to stop and it will be 'rebranded' as Ignition.

Ignition has a similar class called RemoteImageView. Usage is basically the same but it appears they've reworked the back end a bit. I tried it with a ListView that was giving the loading forever problem. Worked for me (although it introduced some other problems).

You can give it a go and see if your problem has been addressed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文