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; 

} 

在此先感謝。

+1

通用圖片下載器和Novoda的圖片加載器不會從網上重新加載***圖片,而是從緩存中獲取圖片(如果圖片已經下載過一次)。 –

+0

我知道他們沒有這樣做,我只是想知道爲什麼圖片需要很長時間才能從緩存中重新載入,當他們的大小不到一兆字節時。 – vivatus

+0

如果你看看這些庫,我敢打賭他們在開始回收位圖之前有一些內存使用限制。他們可能使用API​​來提高這些限制,但否則這將是預期的行爲。看看你的LogCat輸出,他們會收到關於垃圾收集的一些消息。 –

回答

0

如果不將圖像保留在內存中,它們將不得不重新加載(無論是從緩存還是從網絡)。

您可以通過在視圖中顯示視圖之前預加載(綁定)視圖來避免出現這種情況,類似於ViewPager加載頁面的方式,但它與圖像加載器無關。

相關問題