[英]Android ListView scroll smoothly while drawing bitmap in each item view
我有一個ListView,ListView的每個項目視圖在創建和解碼它們時都會繪制幾個位圖。 但是,即使在三星S3上測試時,滾動時也不是很平滑。
我的解決方案是在滾動時使其變為靜態圖像。 但是很難實現。
有沒有簡單的方法或更好的方法來使其性能更好?
主要圖紙代碼:
Bitmap bitmap = decoder.getFrame(index);
if (bitmap != null) {
if (!bitmap.isRecycled()) {
canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(0, 0, fixedSize, fixedSize), paint);
invalidate();
}
}
public Bitmap getFrame(int n) {
if (frameCount <= 0)
return null;
if (n >= frames.size())
return null;
n = n % frameCount;
return ((GifFrame) frames.elementAt(n)).image;
}
列表視圖滾動不流暢,因為您正在UI線程上進行操作。
為了避免這種情況,您應該使用Scroll偵聽器。僅在滾動停止並且僅對可見項執行操作。
檢查API演示示例中的List13.java。
您可能應該使用第三方庫(例如UrlImageViewHelper或Android-Universal-Image-Loader)為您加載圖像。 這些庫通常會處理諸如多線程之類的復雜內容,並查看回收/失效。
試試這個, 使ListView滾動平滑
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.