Android Listview上的通用图像加载程序是laggy

Android Listview上的通用图像加载程序是laggy,android,listview,lag,universal-image-loader,Android,Listview,Lag,Universal Image Loader,我已经确保我只有一个ImageLoader实例,所以我知道这不是问题所在,出于某种原因,它只在显示从web加载的全新图像时才会滞后。所以我假设这与UI因为解码图像而出现口吃有关,但我认为Universal image Loader异步处理所有事情。下面是我的BaseAdapter的getView方法的内容 @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInf

我已经确保我只有一个ImageLoader实例,所以我知道这不是问题所在,出于某种原因,它只在显示从web加载的全新图像时才会滞后。所以我假设这与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;

}

我认为你的问题不是图像加载器。事实上,您没有使用系统返回给您的convertView,因此您根本没有回收视图,只是为列表中的每一行增加了一个新视图

尝试更改
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;

}

我认为你的问题不是图像加载器。事实上,您没有使用系统返回给您的convertView,因此您根本没有回收视图,只是为列表中的每一行增加了一个新视图

尝试更改
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;

}

这就是问题所在!非常感谢你,省得我头疼。这就是问题所在!非常感谢,省得我头疼。包含对ListView主题的宝贵见解(其中许多内容也适用于其他AdapterViews)。我强烈建议您观看本演讲,以便了解驱动优化的机制。包含对ListView主题的宝贵见解(其中许多内容也适用于其他AdapterViews)。我强烈建议您观看本演讲,以便了解驱动优化的机制。