android - Listview 上的通用图像加载器很慢

标签 android listview lag universal-image-loader

我已经确保我只有一个 ImageLoader 实例,所以我知道这不是问题,出于某种原因,它仅在显示从网络加载的全新图像时才会滞后。所以我假设它与 UI 断断续续的事实有关,因为它正在解码图像,但我认为 Universal Image Loader 异步处理所有内容。这是我的 BaseAdapter 的 getView 方法。

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    JSONObject thePost = null;
    try { 
        thePost = mPosts.getJSONObject(position).getJSONObject("data");
    } catch (Exception e) {
        System.out.println("errreoroer");
    }

    LinearLayout postItem = (LinearLayout) inflater.inflate(R.layout.column_post, parent, false);   

    String postThumbnailUrl = null;


    try {

        //parse thumbnail
        postThumbnailUrl = thePost.getString("thumbnail");          

    } catch (Exception e) {}        

    //grab the post view objects

    ImageView postThumbnailView = (ImageView)postItem.findViewById(R.id.thumbnail);

    if (!(postThumbnailUrl.equals("self") || postThumbnailUrl.equals("default") || postThumbnailUrl.equals("nsfw")))
        mImageLoader.displayImage(postThumbnailUrl, postThumbnailView);         


    return postItem;

}

最佳答案

我认为您的问题不是 ImageLoader。事实上,您没有使用系统传回给您的 convertView,因此您根本没有回收 View ,您只是为列表的每一行增加一个新 View 。

尝试更改您的 getView() 方法以使用 convertView:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout postItem = convertView
    if(null == postItem){
        LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        postItem = (LinearLayout) inflater.inflate(R.layout.column_post, parent, false);   
    }

    JSONObject thePost = null;
    try { 
        thePost = mPosts.getJSONObject(position).getJSONObject("data");
    } catch (Exception e) {
        System.out.println("errreoroer");
    }
    String postThumbnailUrl = null;
    try {

        //parse thumbnail
        postThumbnailUrl = thePost.getString("thumbnail");          

    } catch (Exception e) {}        

    //grab the post view objects
    ImageView postThumbnailView = (ImageView)postItem.findViewById(R.id.thumbnail);
    if (!(postThumbnailUrl.equals("self") || postThumbnailUrl.equals("default") || postThumbnailUrl.equals("nsfw")))
        mImageLoader.displayImage(postThumbnailUrl, postThumbnailView);         

    return postItem;

}

关于android - Listview 上的通用图像加载器很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150589/

相关文章:

android - 在公共(public)存储库上为 CircleCI 添加 Google-services.json 以使其运行

android - SoundPool 声音只停止一次?

Android ListView 多次点击项目

android - 如何在垂直 ListView 中制作可水平滚动的项目?

performance - 人类可检测到的最小滞后是多少?

Android - 获取当前时间而不依赖于设备的时钟

android - 在不同的 Activity 或 Fragment 之间共享数据的正确方法是什么?

r - 使用另一个条件过滤某些值和多个先前行

android - AudioTrack 延迟 : obtainBuffer timed out

php - Android:无法使用 php 脚本将图像上传到远程 MySql 数据库