我有一个列表视图,可以将预览图像加载到行中,但是当我向下滚动一点并使行重新出现时,图像似乎会重新加载,就好像它必须再次下载和重新解码一样。我现在正在使用 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;
}
提前致谢。