1

我有一个列表视图,可以将预览图像加载到行中,但是当我向下滚动一点并使行重新出现时,图像似乎会重新加载,就好像它必须再次下载和重新解码一样。我现在正在使用 AQuery 来加载图像,但我已经尝试过 Novoda 的 Image Loader 和 Nostra 的 Universal Image Loader,以及 ImageViews 自己“重新加载”。

这是我简化的 getView 方法(图像被插入底部):

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

FrameLayout postItem = (FrameLayout) convertView;
//final PostHolder holder;
if(null == postItem){
    LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    postItem = (FrameLayout) inflater.inflate(R.layout.column_post, parent, false);   
}

final AQuery aq = new AQuery(postItem);

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

    String postThumbnailUrl = null;
    String author = null;
    String domain = null;
    String subreddit = null;
    int votes = 0;
    int numComments = 0;
    long createdUtc = 0;

    final HashMap<String, Object> postData = new HashMap<String, Object>();

    try {

        postData.put("title", thePost.getString("title"));

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

        postData.put("url", thePost.getString("url"));

        postData.put("permalink", thePost.getString("permalink"));

        postData.put("is_self", thePost.getBoolean("is_self"));

        //whent it was made
        createdUtc = thePost.getLong("created_utc");

        //author
        author = thePost.getString("author");

        subreddit = thePost.getString("subreddit");

        domain = thePost.getString("domain");

        votes = thePost.getInt("ups") - thePost.getInt("downs");

        //num_comments
        numComments = thePost.getInt("num_comments");

    } catch (Exception e) {}    


    //gets the direct url to the image
    mSmartContent.getDirectMedia((String)postData.get("url"), new Callbacks() {

        @Override
        public void callback(Object obj) {

            Bundle cData = (Bundle)obj;

            if (cData.getString("type") == "pic") {

                aq.id(R.id.imagePreview).visibility(View.VISIBLE).image((String)cData.getString("url"));


            } else {

                aq.id(R.id.imagePreview).visibility(View.GONE);

            }


        }



    });


    return postItem;

}

提前致谢。

4

1 回答 1

0

如果不将图像保存在内存中,则必须重新加载它们(无论是从某个缓存还是从网络)。

您可以通过在视图出现在视口中之前预加载(绑定)视图来避免出现这种情况,类似于 ViewPager 加载屏幕外页面的方式,但它与图像加载器无关。

于 2016-11-15T13:30:31.573 回答