1
我有一個列表視圖加載到預覽圖像到行中,但是當我向下滾動一下並使行重新出現時,圖像似乎重新加載自身,就好像它必須再次下載並重新解碼。我現在使用AQuery來加載圖像,但我試過了Novoda的圖像加載器,Nostra的通用圖像加載器和ImageViews「重新加載」自己。ListView「重新載入」滾動的ImageView,我如何防止它做到這一點?
這裏是我的簡單的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;
}
在此先感謝。
通用圖片下載器和Novoda的圖片加載器不會從網上重新加載***圖片,而是從緩存中獲取圖片(如果圖片已經下載過一次)。 –
我知道他們沒有這樣做,我只是想知道爲什麼圖片需要很長時間才能從緩存中重新載入,當他們的大小不到一兆字節時。 – vivatus
如果你看看這些庫,我敢打賭他們在開始回收位圖之前有一些內存使用限制。他們可能使用API來提高這些限制,但否則這將是預期的行爲。看看你的LogCat輸出,他們會收到關於垃圾收集的一些消息。 –