示例#1
0
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
   _animationView.layout(l, t, r, b);
   _textView.layout(l, b - 50, r, b);
   _timeView.layout(l, b - 50, r, b);
   _batteryview.layout(l, b - 50, r, b);
 }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int width = right - left;

    // Take into account left and right padding when laying out the below views.
    mHeaderTextView.layout(
        mHeaderTextIndent + mPaddingLeft,
        0,
        mHeaderTextView.getMeasuredWidth() + mHeaderTextIndent + mPaddingLeft,
        mHeaderBackgroundHeight);

    if (isViewMeasurable(mCountTextView)) {
      mCountTextView.layout(
          width - mPaddingRight - mCountTextView.getMeasuredWidth(),
          0,
          width - mPaddingRight,
          mHeaderBackgroundHeight);
    }

    mHeaderDivider.layout(
        mPaddingLeft,
        mHeaderBackgroundHeight,
        width - mPaddingRight,
        mHeaderBackgroundHeight + mHeaderUnderlineHeight);
  }
    /**
     * Layout the given widgets within the parent.
     *
     * @param l the parent's left border
     * @param t the parent's top border
     * @param r the parent's right border
     * @param b the parent's bottom border
     * @param alignment which side to align the widget to
     */
    void layout(int l, int t, int r, int b, int alignment) {
      this.alignment = alignment;
      final Drawable tabBackground = tab.getBackground();
      final int handleWidth = tabBackground.getIntrinsicWidth();
      final int handleHeight = tabBackground.getIntrinsicHeight();
      final Drawable targetDrawable = target.getDrawable();
      final int targetWidth = targetDrawable.getIntrinsicWidth();
      final int targetHeight = targetDrawable.getIntrinsicHeight();
      final int parentWidth = r - l;
      final int parentHeight = b - t;

      final int leftTarget = (int) (THRESHOLD * parentWidth) - targetWidth + handleWidth / 2;
      final int rightTarget = (int) ((1.0f - THRESHOLD) * parentWidth) - handleWidth / 2;
      final int left = (parentWidth - handleWidth) / 2;
      final int right = left + handleWidth;

      if (alignment == ALIGN_LEFT || alignment == ALIGN_RIGHT) {
        // horizontal
        final int targetTop = (parentHeight - targetHeight) / 2;
        final int targetBottom = targetTop + targetHeight;
        final int top = (parentHeight - handleHeight) / 2;
        final int bottom = (parentHeight + handleHeight) / 2;
        if (alignment == ALIGN_LEFT) {
          tab.layout(0, top, handleWidth, bottom);
          text.layout(0 - parentWidth, top, 0, bottom);
          text.setGravity(Gravity.RIGHT);
          target.layout(leftTarget, targetTop, leftTarget + targetWidth, targetBottom);
          alignment_value = l;
        } else {
          tab.layout(parentWidth - handleWidth, top, parentWidth, bottom);
          text.layout(parentWidth, top, parentWidth + parentWidth, bottom);
          target.layout(rightTarget, targetTop, rightTarget + targetWidth, targetBottom);
          text.setGravity(Gravity.TOP);
          alignment_value = r;
        }
      } else {
        // vertical
        final int targetLeft = (parentWidth - targetWidth) / 2;
        final int targetRight = (parentWidth + targetWidth) / 2;
        final int top = (int) (THRESHOLD * parentHeight) + handleHeight / 2 - targetHeight;
        final int bottom = (int) ((1.0f - THRESHOLD) * parentHeight) - handleHeight / 2;
        if (alignment == ALIGN_TOP) {
          tab.layout(left, 0, right, handleHeight);
          text.layout(left, 0 - parentHeight, right, 0);
          target.layout(targetLeft, top, targetRight, top + targetHeight);
          alignment_value = t;
        } else {
          tab.layout(left, parentHeight - handleHeight, right, parentHeight);
          text.layout(left, parentHeight, right, parentHeight + parentHeight);
          target.layout(targetLeft, bottom, targetRight, bottom + targetHeight);
          alignment_value = b;
        }
      }
    }
          @Override
          public void run() {

            if (mVisible) {
              Canvas canvas = mHolder.lockCanvas();
              WidgetGroup group = new WidgetGroup(getApplicationContext());
              group.setBackgroundColor(Color.WHITE);
              group.setLayoutParams(
                  new LinearLayout.LayoutParams(
                      ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
              group.setAddStatesFromChildren(true);
              group.layout(0, 0, mWidth, mHeight);

              String result =
                  Build.MANUFACTURER
                      + " "
                      + Build.VERSION.RELEASE
                      + " "
                      + DeviceName.getDeviceName();
              TextView osVersion = new TextView(getApplicationContext());
              osVersion.setTextColor(Color.BLACK);
              osVersion.setTextSize(80.f);
              osVersion.setText(result);
              osVersion.setId(R.id.os_version);

              osVersion.layout(0, 0, mWidth, mHeight);
              group.addView(osVersion);

              group.draw(canvas);
              getSurfaceHolder().unlockCanvasAndPost(canvas);
              mHandler.removeCallbacks(draw);
              mHandler.postDelayed(draw, FRAME_DURATION);
            }
          }
示例#5
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // 设置透明alert布局
    int width = r - l;
    int height = b - t;
    int alertLeft = (width - alertWidth) / 2;
    int alertRight = alertLeft + alertWidth;
    int alertTop = (height - alertHeight) / 2;
    int alertBottom = alertTop + alertHeight;
    alert.layout(alertLeft, alertTop, alertRight, alertBottom);

    // 设置转圈圈布局
    int barLeft = (width - barWidth) / 2;
    int barRight = barLeft + barWidth;
    int barTop = (height - barHeight) / 2 - barOffset;
    int barBottom = barTop + barHeight;
    bar.layout(barLeft, barTop, barRight, barBottom);

    // 设置文字布局
    int textLeft = (width - textWidth) / 2;
    int textRight = textLeft + textWidth;
    int textTop = (height - textHeight) / 2 - textOffset;
    int textBottom = textTop + textHeight;
    textView.layout(textLeft, textTop, textRight, textBottom);
  }
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int right = r - l;
    int height = b - t;

    for (int i = 0; i < getChildCount(); i++) {
      // Put all the children outside of the view, then use setPosition
      // to put the ones that need to be seen back. This will be where
      // we set the top and bottom of every view though.
      TextView view = (TextView) getChildAt(i);
      int viewWidth = view.getMeasuredWidth();
      int viewHeight = view.getMeasuredHeight();
      int textTop =
          (height / 2) - (viewHeight - ((view.getLineHeight() * view.getLineCount()) / 2));
      view.layout(right, textTop, right + viewWidth, textTop + viewHeight);
    }
    setPosition(mDisplayedPage, 0, 0);

    mShadow.setBounds(0, 0, right, mShadowHeight);
    mBottomBar.setBounds(0, height - mBottomBarHeight, right, height);

    // Set up the fading edges
    mFadingEdgeLeft.setBounds(0, mShadowHeight, mFadingEdgeLength, height - mBottomBarHeight);
    mFadingEdgeRight.setBounds(
        right - mFadingEdgeLength, mShadowHeight, right, height - mBottomBarHeight);
  }
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
      // Width and height of this ViewGroup.
      final int width = right - left;
      final int height = bottom - top;

      // The size of the image, given as a fraction of the dimension as a ViewGroup. We multiply
      // both width and heading with this number to compute the image's bounding box. Inside the
      // box, the image is the horizontally and vertically centered.
      final float imageSize = 0.12f;

      // The fraction of this ViewGroup's height by which we shift the image off the ViewGroup's
      // center. Positive values shift downwards, negative values shift upwards.
      final float verticalImageOffset = -0.07f;

      // Vertical position of the text, specified in fractions of this ViewGroup's height.
      final float verticalTextPos = 0.52f;

      // Layout ImageView
      float imageMargin = (1.0f - imageSize) / 2.0f;
      float leftMargin = (int) (width * (imageMargin + offset));
      float topMargin = (int) (height * (imageMargin + verticalImageOffset));
      imageView.layout(
          (int) leftMargin, (int) topMargin,
          (int) (leftMargin + width * imageSize), (int) (topMargin + height * imageSize));

      // Layout TextView
      leftMargin = offset * width;
      topMargin = height * verticalTextPos;
      textView.layout(
          (int) leftMargin, (int) topMargin,
          (int) (leftMargin + width), (int) (topMargin + height * (1.0f - verticalTextPos)));
    }
  private void drawLocalityLabel(Canvas canvas) {
    TextView textView = new TextView(getContext());
    int width = this.width;
    int height = (int) (60);
    textView.layout(0, 0, width, height);

    switch (currentLocationID) {
      case 0:
        textView.setText("Current Locality: Room 340");
        break;
      case 1:
        textView.setText("Current Locality: Room 343");
        break;
      case 2:
        textView.setText("Current Locality: Room 344");
        break;
      case 3:
        textView.setText("Current Locality: Hallway");
        break;
    }
    textView.setBackgroundColor(Color.parseColor(borderColor));
    textView.setTextColor(Color.WHITE);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    // textView.setTextAlignment(TEXT_ALIGNMENT_CENTER);
    textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    Bitmap bitmapText = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvasText = new Canvas(bitmapText);
    textView.draw(canvasText);

    canvas.drawBitmap(bitmapText, 0, this.height - 160, null);
  }
示例#9
0
  void updateTextPositions(int position, float positionOffset) {
    if (position != mLastKnownCurrentPage) {
      updateText(position, mPager.getAdapter());
    } else if (positionOffset == mLastKnownPositionOffset) {
      return;
    }

    mUpdatingPositions = true;

    final int prevWidth = mPrevText.getMeasuredWidth();
    final int currWidth = mCurrText.getMeasuredWidth();
    final int nextWidth = mNextText.getMeasuredWidth();
    final int halfCurrWidth = currWidth / 2;

    final int stripWidth = getWidth();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int textPaddedLeft = paddingLeft + halfCurrWidth;
    final int textPaddedRight = paddingRight + halfCurrWidth;
    final int contentWidth = stripWidth - textPaddedLeft - textPaddedRight;

    float currOffset = positionOffset + 0.5f;
    if (currOffset > 1.f) {
      currOffset -= 1.f;
    }
    final int currCenter = stripWidth - textPaddedRight - (int) (contentWidth * currOffset);
    final int currLeft = currCenter - currWidth / 2;
    final int currRight = currLeft + currWidth;

    mCurrText.layout(currLeft, paddingTop, currRight, paddingTop + mCurrText.getMeasuredHeight());

    final int prevLeft = Math.min(paddingLeft, currLeft - mScaledTextSpacing - prevWidth);
    mPrevText.layout(
        prevLeft, paddingTop, prevLeft + prevWidth, paddingTop + mPrevText.getMeasuredHeight());

    final int nextLeft =
        Math.max(stripWidth - paddingRight - nextWidth, currRight + mScaledTextSpacing);
    mNextText.layout(
        nextLeft, paddingTop, nextLeft + nextWidth, paddingTop + mNextText.getMeasuredHeight());

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
  }
示例#10
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int childRight = right - left;
    int childBottom = bottom - top;
    int childLeft = 0;
    int childTop = 0;

    int y = (childBottom - mAvatarSize) / 2;
    childLeft += mSpacing;
    mAvatarDrawable.setBounds(childLeft, y, childLeft + mAvatarSize, y + mAvatarSize);

    childLeft += mAvatarSize + mSpacing;

    if (mButton != null) {
      mButton.layout(childRight - mButtonSize, childTop, childRight, childBottom);
      childRight -= mButtonSize;
    }

    if (mNameView.getVisibility() == View.VISIBLE) {
      if (mAddressView.getVisibility() == View.VISIBLE) {
        childTop =
            (childBottom - mNameView.getMeasuredHeight() - mAddressView.getMeasuredHeight()) / 2;
        mNameView.layout(
            childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight());
        childTop += mNameView.getMeasuredHeight();
        mAddressView.layout(
            childLeft,
            childTop,
            childRight - mSpacing,
            childTop + mAddressView.getMeasuredHeight());
      } else {
        childTop = (childBottom - mNameView.getMeasuredHeight()) / 2;
        mNameView.layout(
            childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight());
      }
    } else if (mAddressView.getVisibility() == View.VISIBLE) {
      childTop = (childBottom - mAddressView.getMeasuredHeight()) / 2;
      mAddressView.layout(
          childLeft, childTop, childRight - mSpacing, childTop + mAddressView.getMeasuredHeight());
    }
  }
  public int captureBitmapCache(String in) {
    TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview);
    String tvText = tv.getText().toString();
    float tvTextSize = tv.getTextSize();
    int tvColor = tv.getCurrentTextColor();
    Bitmap bitmap = null;

    tv.setTextSize(36);
    tv.setTextColor(Color.CYAN);
    tv.setTypeface(Typeface.SANS_SERIF);

    tv.setText(in);

    while (bitmap == null) {
      // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null
      tv.measure(
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
      tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

      tv.setDrawingCacheEnabled(true);
      tv.buildDrawingCache(true);
      bitmap = Bitmap.createBitmap(tv.getDrawingCache());
      tv.destroyDrawingCache();
      tv.setDrawingCacheEnabled(false);
    }

    FileOutputStream fos = null;
    int res = -1;
    try {
      fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME);
      if (fos != null) {
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
        fos.close();
        res = 0;
      }
    } catch (Throwable e) {
      Log.i(MyApp.TAG, e.getMessage().toString());
      res = -1;
    }

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize);
    tv.setTypeface(Typeface.MONOSPACE);
    tv.setText(tvText);
    tv.setTextColor(tvColor);
    return res;
  }
示例#12
0
  @Override
  protected void onDraw(Canvas c, OpenStreetMapView osmv) {
    if (this.mLocation != null) {
      mT.setText(mDescr);
      mT.measure(0, 0);
      mT.layout(0, 0, mT.getMeasuredWidth(), mT.getMeasuredHeight());

      final OpenStreetMapViewProjection pj = osmv.getProjection();
      final Point screenCoords = new Point();
      pj.toPixels(this.mLocation, screenCoords);

      c.save();
      c.rotate(osmv.getBearing(), screenCoords.x, screenCoords.y);
      c.translate(screenCoords.x - 12, screenCoords.y - mT.getMeasuredHeight() + 2);
      mT.draw(c);
      c.restore();
    }
  }
示例#13
0
  private void drawTextCanvas(Canvas canvas, String text) {
    // TODO Auto-generated method stub

    // set color the background
    canvas.drawPaint(paint);

    // Setup textView like your normanlly would with your activity context
    TextView tv = new TextView(mContext);

    tv.setMaxWidth(300);

    // setup Text
    tv.setText(mText);

    // set Textcolor
    tv.setTextColor(Color.BLUE);

    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);

    // enable SetDrawing cache
    tv.setDrawingCacheEnabled(true);

    tv.measure(
        MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(canvas.getHeight(), MeasureSpec.EXACTLY));
    tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

    Bitmap bm =
        BitmapFactory.decodeResource(getResources(), R.drawable.khung_xanh)
            .copy(Bitmap.Config.ARGB_8888, true);
    bm =
        Bitmap.createScaledBitmap(
            bm,
            tv.getMeasuredWidth() + 40,
            (int) ((int) tv.getLineCount() * (tv.getLineHeight() + 8)),
            true);
    canvas.drawBitmap(bm, 0, 0, paint);

    // draw bitmap from drawingcache to the canvas
    canvas.drawBitmap(tv.getDrawingCache(), 20, 20, paint);

    // disable drawing cache
    tv.setDrawingCacheEnabled(false);
  }
  @Override
  protected void onLayout(
      final boolean changed, final int left, final int top, final int right, final int bottom) {
    final int cellWidth = getMeasuredWidth() / GRID_WIDTH;
    final int cellHeight = getMeasuredHeight() / GRID_HEIGHT;
    final int padding =
        getResources().getDimensionPixelOffset(R.dimen.multiple_attachment_preview_padding);
    final int count = mPreviewViews.size();
    for (int i = 0; i < count; i++) {
      final ViewWrapper viewWrapper = mPreviewViews.get(i);
      final View view = viewWrapper.view;
      final Tile imageTile = mCurrentLayout.tiles.get(i);
      final int tileLeft = imageTile.startX * cellWidth;
      final int tileTop = imageTile.startY * cellHeight;
      view.layout(
          tileLeft + padding,
          tileTop + padding,
          tileLeft + view.getMeasuredWidth(),
          tileTop + view.getMeasuredHeight());
      if (viewWrapper.needsSlideAnimation) {
        trySlideAttachmentView(viewWrapper);
        viewWrapper.needsSlideAnimation = false;
      } else {
        viewWrapper.prevLeft = view.getLeft();
        viewWrapper.prevTop = view.getTop();
        viewWrapper.prevWidth = view.getWidth();
        viewWrapper.prevHeight = view.getHeight();
      }

      if (i == count - 1 && mPlusTextView != null) {
        // The plus text view always covers the last attachment.
        mPlusTextView.layout(
            tileLeft + padding,
            tileTop + padding,
            tileLeft + mPlusTextView.getMeasuredWidth(),
            tileTop + mPlusTextView.getMeasuredHeight());
      }
    }
  }
示例#15
0
  public void setPosition(int position, float positionOffset, int positionOffsetPixels) {
    mTouchZonesAccurate = false;
    int width = getWidth();
    int center = width / 2;

    // Move the view at position. This will be the label for the left
    // of the two fragments that may be on the screen
    if (position >= 0 && position < getChildCount()) {
      TextView view = (TextView) getChildAt(position);
      int viewWidth = view.getWidth();
      int leftMin = 0;
      if (position + 1 < getChildCount()) {
        int nextViewWidth = getChildAt(position + 1).getWidth();
        leftMin = Math.min(0, center - (nextViewWidth / 2) - mPaddingPush - viewWidth);
      }
      int leftMax = center - (viewWidth / 2);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mInactiveTextColor.red, mActiveTextColor.red),
              map(positionOffset, 1, 0, mInactiveTextColor.green, mActiveTextColor.green),
              map(positionOffset, 1, 0, mInactiveTextColor.blue, mActiveTextColor.blue)));
    }

    // Move the view at position + 1. This will be the label for the
    // right of the two fragments that may be visible on screen
    if ((position + 1) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 1);
      int viewWidth = view.getWidth();
      int prevViewWidth = getChildAt(position).getWidth();
      int leftMin = center - (viewWidth / 2);
      int leftMax = Math.max(width - viewWidth, center + (prevViewWidth / 2) + mPaddingPush);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mActiveTextColor.red, mInactiveTextColor.red),
              map(positionOffset, 1, 0, mActiveTextColor.green, mInactiveTextColor.green),
              map(positionOffset, 1, 0, mActiveTextColor.blue, mInactiveTextColor.blue)));
    }

    // Move the view at position - 1. This will be the label for the
    // fragment that is off the screen to the left, if it exists
    if (position > 0) {
      TextView view = (TextView) getChildAt(position - 1);
      int plusOneLeft = getChildAt(position).getLeft();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (plusOneLeft < newLeft + viewWidth + mPaddingPush || newLeft < 0) {
        newLeft = Math.min(0, plusOneLeft - viewWidth - mPaddingPush);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 1, 0, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Move the view at position + 2. This will be the label for the
    // fragment that is off the screen to the right, if it exists
    if ((position + 2) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 2);
      int minusOneRight = getChildAt(position + 1).getRight();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (minusOneRight > (newLeft - mPaddingPush) || newLeft + viewWidth > width) {
        newLeft = Math.max(minusOneRight + mPaddingPush, width - viewWidth);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 0, 1, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Draw the tab under the active or oncoming TextView based on the
    // positionOffset
    View view = getChildAt(positionOffset < 0.5f ? position : position + 1);
    int viewLeft = view.getLeft();
    int viewRight = view.getRight();
    float percent = (Math.abs(positionOffset - 0.5f) / 0.5f);
    int tabHeight = (int) (mTabHeight * percent);
    int alpha = (int) (255 * percent);
    mTabDrawable.setBounds(
        viewLeft - mTabPadding, getHeight() - tabHeight, viewRight + mTabPadding, getHeight());
    mTabDrawable.setAlpha(alpha);
  }
示例#16
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int width = r - l;
    final int height = b - t;
    final int imageWidth = mImage.getMeasuredWidth();
    final int imageHeight = mImage.getMeasuredHeight();
    final int textWidth = mText.getMeasuredWidth();
    final int textHeight = mText.getMeasuredHeight();
    int left = getPaddingLeft();
    int top = getPaddingTop();
    int right = r - getPaddingRight();
    int bottom = b - getPaddingBottom();

    /*added by chengran sun for better performing*/
    int widthNoPadding = width - getPaddingLeft() - getPaddingRight();
    int heightNoPadding = height - getPaddingTop() - getPaddingBottom();

    if (POSITION_LEFT.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            left,
            (heightNoPadding - textHeight) / 2,
            left += textWidth,
            (heightNoPadding + textHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left += textWidth, top + textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(left, bottom - textHeight, left += textWidth, bottom);
      }

      if (!mNeedLayout) {
        return;
      }

      left += mSpacing;

      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            left,
            (heightNoPadding - imageHeight) / 2,
            left += imageWidth,
            (heightNoPadding + imageHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left += imageWidth, top + imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(left, bottom - imageHeight, left += imageWidth, bottom);
      }
    } else if (POSITION_RIGHT.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            left,
            (heightNoPadding - imageHeight) / 2,
            left += imageWidth,
            (heightNoPadding + imageHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left += imageWidth, top + imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(left, bottom - imageHeight, left += imageWidth, bottom);
      }

      if (!mNeedLayout) {
        return;
      }

      left += mSpacing;

      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            left,
            (heightNoPadding - textHeight) / 2,
            left += textWidth,
            (heightNoPadding + textHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left += textWidth, top + textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(left, bottom - textHeight, left += textWidth, bottom);
      }
    } else if (POSITION_TOP.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            (widthNoPadding - textWidth) / 2,
            top,
            (widthNoPadding + textWidth) / 2,
            top += textHeight);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left + textWidth, top += textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(right - textWidth, top, right, top += textHeight);
      }

      if (!mNeedLayout) {
        return;
      }

      top += mSpacing;

      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            (widthNoPadding - imageWidth) / 2,
            top,
            (widthNoPadding + imageWidth) / 2,
            top += imageHeight);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left + imageWidth, top += imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(right - imageWidth, top, right, top += imageHeight);
      }
    } else if (POSITION_BOTTOM.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            (widthNoPadding - imageWidth) / 2,
            top,
            (widthNoPadding + imageWidth) / 2,
            top += imageHeight);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left + imageWidth, top += imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(right - imageWidth, top, right, top += imageHeight);
      }

      if (!mNeedLayout) {
        return;
      }

      top += mSpacing;

      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            (widthNoPadding - textWidth) / 2,
            top,
            (widthNoPadding + textWidth) / 2,
            top += textHeight);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left + textWidth, top += textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(right - textWidth, top, right, top += textHeight);
      }
    }
  }