Esempio n. 1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int width;
    int height;

    if (mAction.getVisibility() == View.VISIBLE) {
      mAction.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), heightMeasureSpec);
      int padding = mIsRtl ? mText.getPaddingLeft() : mText.getPaddingRight();
      mText.measure(
          MeasureSpec.makeMeasureSpec(
              widthSize - (mAction.getMeasuredWidth() - padding), widthMode),
          heightMeasureSpec);
      width = mText.getMeasuredWidth() + mAction.getMeasuredWidth() - padding;
    } else {
      mText.measure(MeasureSpec.makeMeasureSpec(widthSize, widthMode), heightMeasureSpec);
      width = mText.getMeasuredWidth();
    }

    height = Math.max(mText.getMeasuredHeight(), mAction.getMeasuredHeight());

    switch (widthMode) {
      case MeasureSpec.AT_MOST:
        width = Math.min(widthSize, width);
        break;
      case MeasureSpec.EXACTLY:
        width = widthSize;
        break;
    }

    switch (heightMode) {
      case MeasureSpec.AT_MOST:
        height = Math.min(heightSize, height);
        break;
      case MeasureSpec.EXACTLY:
        height = heightSize;
        break;
    }

    if (mMaxHeight > 0) height = Math.min(mMaxHeight, height);

    if (mMinHeight > 0) height = Math.max(mMinHeight, height);

    setMeasuredDimension(width, height);
  }
Esempio n. 2
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int childLeft = getPaddingLeft();
    int childRight = r - l - getPaddingRight();
    int childTop = getPaddingTop();
    int childBottom = b - t - getPaddingBottom();

    if (mAction.getVisibility() == View.VISIBLE) {
      if (mIsRtl) {
        mAction.layout(childLeft, childTop, childLeft + mAction.getMeasuredWidth(), childBottom);
        childLeft += mAction.getMeasuredWidth() - mText.getPaddingLeft();
      } else {
        mAction.layout(childRight - mAction.getMeasuredWidth(), childTop, childRight, childBottom);
        childRight -= mAction.getMeasuredWidth() - mText.getPaddingRight();
      }
    }

    mText.layout(childLeft, childTop, childRight, childBottom);
  }
Esempio n. 3
0
 /**
  * Set the vertical padding between this SnackBar and it's text and button.
  *
  * @param padding
  * @return This SnackBar for chaining methods.
  */
 public SnackBar verticalPadding(int padding) {
   mText.setPadding(mText.getPaddingLeft(), padding, mText.getPaddingRight(), padding);
   mAction.setPadding(mAction.getPaddingLeft(), padding, mAction.getPaddingRight(), padding);
   return this;
 }