コード例 #1
0
  /**
   * 浣胯疆瀛愬け鏁�
   *
   * @param clearCaches if true then cached views will be clear
   */
  public void invalidateWheel(boolean clearCaches) {
    if (clearCaches) {
      recycle.clearAll();
      if (itemsLayout != null) {
        itemsLayout.removeAllViews();
      }
      scrollingOffset = 0;
    } else if (itemsLayout != null) {
      // cache all items
      recycle.recycleItems(itemsLayout, firstItem, new ItemsRange());
    }

    invalidate();
  }
コード例 #2
0
  /** 閲嶅缓鏂扮殑璁$畻鏂规硶 */
  private void buildViewForMeasuring() {
    // clear all items
    if (itemsLayout != null) {
      recycle.recycleItems(itemsLayout, firstItem, new ItemsRange());
    } else {
      createItemsLayout();
    }

    // add views
    int addItems = visibleItems / 2;
    for (int i = currentItem + addItems; i >= currentItem - addItems; i--) {
      if (addViewItem(i, true)) {
        firstItem = i;
      }
    }
  }
コード例 #3
0
  /**
   * 濡傛灉鏈夊繀瑕侀噸鏂伴噸寤鸿疆瀛愮殑item鍜岀紦瀛樻病鏈夌敤鐨刬tem
   *
   * @return true if items are rebuilt
   */
  private boolean rebuildItems() {
    boolean updated = false;
    ItemsRange range = getItemsRange();
    if (itemsLayout != null) {
      int first = recycle.recycleItems(itemsLayout, firstItem, range);
      updated = firstItem != first;
      firstItem = first;
    } else {
      createItemsLayout();
      updated = true;
    }

    if (!updated) {
      updated = firstItem != range.getFirst() || itemsLayout.getChildCount() != range.getCount();
    }

    if (firstItem > range.getFirst() && firstItem <= range.getLast()) {
      for (int i = firstItem - 1; i >= range.getFirst(); i--) {
        if (!addViewItem(i, true)) {
          break;
        }
        firstItem = i;
      }
    } else {
      firstItem = range.getFirst();
    }

    int first = firstItem;
    for (int i = itemsLayout.getChildCount(); i < range.getCount(); i++) {
      if (!addViewItem(firstItem + i, false) && itemsLayout.getChildCount() == 0) {
        first++;
      }
    }
    firstItem = first;

    return updated;
  }