コード例 #1
0
  private int measureHeightOfChildren(
      int widthMeasureSpec,
      int startPosition,
      int endPosition,
      final int maxHeight,
      int disallowPartialChildPosition) {

    final ListAdapter adapter = mAdapter;
    if (adapter == null) {
      return mDropDownList.getListPaddingTop() + mDropDownList.getListPaddingBottom();
    }

    // Include the padding of the list
    int returnedHeight = mDropDownList.getListPaddingTop() + mDropDownList.getListPaddingBottom();
    final int dividerHeight =
        ((mDropDownList.getDividerHeight() > 0) && mDropDownList.getDivider() != null)
            ? mDropDownList.getDividerHeight()
            : 0;
    // The previous height value that was less than maxHeight and contained
    // no partial children
    int prevHeightWithoutPartialChild = 0;
    int i;
    View child;

    // mItemCount - 1 since endPosition parameter is inclusive
    endPosition = (endPosition == -1 /*NO_POSITION*/) ? adapter.getCount() - 1 : endPosition;

    for (i = startPosition; i <= endPosition; ++i) {
      child = mAdapter.getView(i, null, mDropDownList);
      if (mDropDownList.getCacheColorHint() != 0) {
        child.setDrawingCacheBackgroundColor(mDropDownList.getCacheColorHint());
      }

      measureScrapChild(child, i, widthMeasureSpec);

      if (i > 0) {
        // Count the divider for all but one child
        returnedHeight += dividerHeight;
      }

      returnedHeight += child.getMeasuredHeight();

      if (returnedHeight >= maxHeight) {
        // We went over, figure out which height to return.  If returnedHeight > maxHeight,
        // then the i'th position did not fit completely.
        return (disallowPartialChildPosition >= 0) // Disallowing is enabled (> -1)
                && (i > disallowPartialChildPosition) // We've past the min pos
                && (prevHeightWithoutPartialChild > 0) // We have a prev height
                && (returnedHeight != maxHeight) // i'th child did not fit completely
            ? prevHeightWithoutPartialChild
            : maxHeight;
      }

      if ((disallowPartialChildPosition >= 0) && (i >= disallowPartialChildPosition)) {
        prevHeightWithoutPartialChild = returnedHeight;
      }
    }

    // At this point, we went through the range of children, and they each
    // completely fit, so return the returnedHeight
    return returnedHeight;
  }