Gallery3D各個介面可見範圍計算方法
文章分類:移動開發
computeVisibleRange演算法分析:
第1步,計算出left,right,bottom,top
第2步,計算出numSlots,併除於2賦值給index
第3步,由index得position,判斷position是否在第1步計算出的範圍內,是的話,就把第2步計算得出的中間的index賦值給 firstVisibleSlotIndex,lastVisibleSlotIndex,否則,根據滑動視窗演算法改變index直到求組所需index
第4步,在while迴圈中,用第3步得到的firstVisibleSlotIndex求出position,進行和第2步相反的判斷,即 position若不在可視範圍內,則將相應的index給firstVisibleSlotIndex,否則減 firstVisibleSlotIndex,直到找到最小的可視範圍內的index作為firstVisibleSlotIndex。
第5步,在while迴圈中,用第3步得到的lastVisibleSlotIndex求出position,進行和第2步相反的判斷,即 position若不在可視範圍內,則將相應的index給lastVisibleSlotIndex,否則增 lastVisibleSlotIndex,直到找到可視範圍內的最大的index作為lastVisibleSlotIndex。
第6步,進行firstVisibleSlotIndex,lastVisibleSlotIndex的越界判斷。 outBufferedVisibleRange對應的是可見的。outBufferedVisibleRange對應的是0~檔案夾的最大數。
computeVisibleItems演算法分析:
第1步 由slot計算出position,set,當前set不為空白且slot在有效範圍,建立bestItems,計算sortedIntersection
第2步 計算這個slotindex中的圖片數目,取這個檔案中的前12張圖片加到bestItems.
第3步 取bestItems裡的圖片對應的displayList中的displayItem,並賦值給displayItems數組,同時儲存 position,及j,j是bestItems數組中一項,範圍是0~12。
第四步 對於每一個檔案夾,要在displayItems裡有對應的12項,當檔案夾內圖片不足12時,餘下的用null填充。
當繪製縮圖介面時,有些不同
在第1步中,slotindex不再表示檔案夾,這時表示具體某一張圖片了,所以由slot得到的set裡始終只有1項,且會調 ArrayUtils.computeSortedIntersection(visibleItems, items, MAX_ITEMS_PER_SLOT, bestItems, sTempHash);給bestItems賦值,這樣第2步就在bestItems加項動作不執行。