private int measure(int measureSpec) {
    int result = 0;

    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.UNSPECIFIED) {
      result = 200;
    } else {
      result = specSize;
    }
    return result;
  }
Esempio n. 2
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // Try for a width based on our minimum
    int minw = getPaddingLeft() + getPaddingRight() + getSuggestedMinimumWidth();

    int w = Math.max(minw, MeasureSpec.getSize(widthMeasureSpec));

    // Whatever the width ends up being, ask for a height that would let the pie
    // get as big as it can
    int minh = (w - (int) mTextWidth) + getPaddingBottom() + getPaddingTop();
    int h = Math.min(MeasureSpec.getSize(heightMeasureSpec), minh);

    setMeasuredDimension(w, h);
  }
 private View makeView(int row, int column, int w, int h) {
   final int itemViewType = adapter.getItemViewType(row, column);
   final View recycledView;
   if (itemViewType == TableAdapter.IGNORE_ITEM_VIEW_TYPE) {
     recycledView = null;
   } else {
     recycledView = recycler.getRecycledView(itemViewType);
   }
   final View view = adapter.getView(row, column, recycledView, this);
   view.setTag(R.id.tag_type_view, itemViewType);
   view.setTag(R.id.tag_row, row);
   view.setTag(R.id.tag_column, column);
   view.measure(
       MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY),
       MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY));
   addTableView(view, row, column);
   return view;
 }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    final int w;
    final int h;

    if (adapter != null) {
      this.rowCount = adapter.getRowCount();
      this.columnCount = adapter.getColumnCount();

      widths = new int[columnCount + 1];
      for (int i = -1; i < columnCount; i++) {
        widths[i + 1] += adapter.getWidth(i);
      }
      heights = new int[rowCount + 1];
      for (int i = -1; i < rowCount; i++) {
        heights[i + 1] += adapter.getHeight(i);
      }

      if (widthMode == MeasureSpec.AT_MOST) {
        w = Math.min(widthSize, sumArray(widths));
      } else if (widthMode == MeasureSpec.UNSPECIFIED) {
        w = sumArray(widths);
      } else {
        w = widthSize;
        int sumArray = sumArray(widths);
        if (sumArray < widthSize) {
          final float factor = widthSize / (float) sumArray;
          for (int i = 1; i < widths.length; i++) {
            widths[i] = Math.round(widths[i] * factor);
          }
          widths[0] = widthSize - sumArray(widths, 1, widths.length - 1);
        }
      }

      if (heightMode == MeasureSpec.AT_MOST) {
        h = Math.min(heightSize, sumArray(heights));
      } else if (heightMode == MeasureSpec.UNSPECIFIED) {
        h = sumArray(heights);
      } else {
        h = heightSize;
      }
    } else {
      if (heightMode == MeasureSpec.AT_MOST || widthMode == MeasureSpec.UNSPECIFIED) {
        w = 0;
        h = 0;
      } else {
        w = widthSize;
        h = heightSize;
      }
    }

    if (firstRow >= rowCount || getMaxScrollY() - getActualScrollY() < 0) {
      firstRow = 0;
      scrollY = Integer.MAX_VALUE;
    }
    if (firstColumn >= columnCount || getMaxScrollX() - getActualScrollX() < 0) {
      firstColumn = 0;
      scrollX = Integer.MAX_VALUE;
    }

    setMeasuredDimension(w, h);
  }