android.graphics.Rect.width()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中android.graphics.Rect.width方法的一些代码示例,展示了Rect.width的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rect.width方法的具体详情如下:
包路径:android.graphics.Rect
类名称:Rect
方法名:width

Rect.width介绍

暂无

代码示例

代码示例来源:origin: nickbutcher/plaid

private void onBoundsChanged() {
  mDrawTitle = mCollapsedBounds.width() > 0 && mCollapsedBounds.height() > 0
      && mExpandedBounds.width() > 0 && mExpandedBounds.height() > 0;
}

代码示例来源:origin: stackoverflow.com

Rect bounds = new Rect();
Paint textPaint = textView.getPaint();
textPaint.getTextBounds(text, 0, text.length(), bounds);
int height = bounds.height();
int width = bounds.width();

代码示例来源:origin: Bigkoo/Android-PickerView

private void measuredOutContentStart(String content) {
  Rect rect = new Rect();
  paintOuterText.getTextBounds(content, 0, content.length(), rect);
  switch (mGravity) {
    case Gravity.CENTER:
      if (isOptions || label == null || label.equals("") || !isCenterLabel) {
        drawOutContentStart = (int) ((measuredWidth - rect.width()) * 0.5);
      } else {//只显示中间label时,时间选择器内容偏左一点,留出空间绘制单位标签
        drawOutContentStart = (int) ((measuredWidth - rect.width()) * 0.25);
      }
      break;
    case Gravity.LEFT:
      drawOutContentStart = 0;
      break;
    case Gravity.RIGHT:
      drawOutContentStart = measuredWidth - rect.width() - (int) CENTER_CONTENT_OFFSET;
      break;
  }
}

代码示例来源:origin: stackoverflow.com

Point displaySize = new Point();
activity.getWindowManager().getDefaultDisplay().getRealSize(displaySize);

Rect windowSize = new Rect();
ctivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(windowSize);

int width = displaySize.x - Math.abs(windowSize.width());
int height = displaySize.y - Math.abs(windowSize.height());
return new Point(width, height);

代码示例来源:origin: facebook/litho

private boolean animatingRootBoundsFromZero(Rect currentVisibleArea) {
 return !mHasMounted
   && ((mRootHeightAnimation != null && currentVisibleArea.height() == 0)
     || (mRootWidthAnimation != null && currentVisibleArea.width() == 0));
}

代码示例来源:origin: Bigkoo/Android-PickerView

private void measuredCenterContentStart(String content) {
  Rect rect = new Rect();
  paintCenterText.getTextBounds(content, 0, content.length(), rect);
  switch (mGravity) {
    case Gravity.CENTER://显示内容居中
      if (isOptions || label == null || label.equals("") || !isCenterLabel) {
        drawCenterContentStart = (int) ((measuredWidth - rect.width()) * 0.5);
      } else {//只显示中间label时,时间选择器内容偏左一点,留出空间绘制单位标签
        drawCenterContentStart = (int) ((measuredWidth - rect.width()) * 0.25);
      }
      break;
    case Gravity.LEFT:
      drawCenterContentStart = 0;
      break;
    case Gravity.RIGHT://添加偏移量
      drawCenterContentStart = measuredWidth - rect.width() - (int) CENTER_CONTENT_OFFSET;
      break;
  }
}

代码示例来源:origin: stackoverflow.com

private Rect r = new Rect();

private void drawCenter(Canvas canvas, Paint paint, String text) {
  canvas.getClipBounds(r);
  int cHeight = r.height();
  int cWidth = r.width();
  paint.setTextAlign(Paint.Align.LEFT);
  paint.getTextBounds(text, 0, text.length(), r);
  float x = cWidth / 2f - r.width() / 2f - r.left;
  float y = cHeight / 2f + r.height() / 2f - r.bottom;
  canvas.drawText(text, x, y, paint);
}

代码示例来源:origin: davemorrissey/subsampling-scale-image-view

private void setInvariants() {
  if (this.sRegion != null) {
    this.tile = true;
    this.sWidth = this.sRegion.width();
    this.sHeight = this.sRegion.height();
  }
}

代码示例来源:origin: Bigkoo/Android-PickerView

/**
 * reset the size of the text Let it can fully display
 *
 * @param contentText item text content.
 */
private void reMeasureTextSize(String contentText) {
  Rect rect = new Rect();
  paintCenterText.getTextBounds(contentText, 0, contentText.length(), rect);
  int width = rect.width();
  int size = textSize;
  while (width > measuredWidth) {
    size--;
    //设置2条横线中间的文字大小
    paintCenterText.setTextSize(size);
    paintCenterText.getTextBounds(contentText, 0, contentText.length(), rect);
    width = rect.width();
  }
  //设置2条横线外面的文字大小
  paintOuterText.setTextSize(size);
}

代码示例来源:origin: stackoverflow.com

Rect bounds = new Rect();
Paint textPaint = textView.getPaint();
textPaint.getTextBounds(text,0,text.length(),bounds);
int height = bounds.height();
int width = bounds.width();

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * calculates the approximate size of a text, depending on a demo text
 * avoid repeated calls (e.g. inside drawing methods)
 *
 * @param paint
 * @param demoText
 * @param outputFSize An output variable, modified by the function.
 */
public static void calcTextSize(Paint paint, String demoText, FSize outputFSize) {
  Rect r = mCalcTextSizeRect;
  r.set(0,0,0,0);
  paint.getTextBounds(demoText, 0, demoText.length(), r);
  outputFSize.width = r.width();
  outputFSize.height = r.height();
}

代码示例来源:origin: stackoverflow.com

protected void onDraw(Canvas canvas){
  final String s = "Hello. I'm some text!";
  Paint p = new Paint();
  Rect bounds = new Rect();
  p.setTextSize(60);
  p.getTextBounds(s, 0, s.length(), bounds);
  float mt = p.measureText(s);
  int bw = bounds.width();
  Log.i("LCG", String.format(
    "measureText %f, getTextBounds %d (%s)",
    mt,
    bw, bounds.toShortString())
  );
  bounds.offset(0, -bounds.top);
  p.setStyle(Style.STROKE);
  canvas.drawColor(0xff000080);
  p.setColor(0xffff0000);
  canvas.drawRect(bounds, p);
  p.setColor(0xff00ff00);
  canvas.drawText(s, 0, bounds.bottom, p);
}

代码示例来源:origin: stackoverflow.com

Rect rectf = new Rect();
<imageView>or<view>.getLocalVisibleRect(rectf);

Log.d("WIDTH        :", String.valueOf(rectf.width()));
Log.d("HEIGHT       :", String.valueOf(rectf.height()));
Log.d("left         :", String.valueOf(rectf.left));
Log.d("right        :", String.valueOf(rectf.right));
Log.d("top          :", String.valueOf(rectf.top));
Log.d("bottom       :", String.valueOf(rectf.bottom));

代码示例来源:origin: ArthurHub/Android-Image-Cropper

/**
 * Fix the given rectangle if it doesn't confirm to aspect ration rule.<br>
 * Make sure that width and height are equal if 1:1 fixed aspect ratio is requested.
 */
private static void fixRectForAspectRatio(Rect rect, int aspectRatioX, int aspectRatioY) {
 if (aspectRatioX == aspectRatioY && rect.width() != rect.height()) {
  if (rect.height() > rect.width()) {
   rect.bottom -= rect.height() - rect.width();
  } else {
   rect.right -= rect.width() - rect.height();
  }
 }
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

/**
 * 根据文字的长度 重新设置文字的大小 让其能完全显示
 */
private void remeasureTextSize(String contentText) {
  Rect rect = new Rect();
  paintCenterText.getTextBounds(contentText, 0, contentText.length(), rect);
  int width = rect.width();
  int size = textSize;
  while (width > measuredWidth) {
    size--;
    //设置2条横线中间的文字大小
    paintCenterText.setTextSize(size);
    paintCenterText.getTextBounds(contentText, 0, contentText.length(), rect);
    width = rect.width();
  }
  //设置2条横线外面的文字大小
  paintOuterText.setTextSize(size);
}

代码示例来源:origin: stackoverflow.com

Paint paint = new Paint();
Rect bounds = new Rect();

int text_height = 0;
int text_width = 0;

paint.setTypeface(Typeface.DEFAULT);// your preference here
paint.setTextSize(25);// have this the same as your text size

String text = "Some random text";

paint.getTextBounds(text, 0, text.length(), bounds);

text_height =  bounds.height();
text_width =  bounds.width();

代码示例来源:origin: alexvasilkov/GestureViews

private void calculateOutsideBounds(RectF area, Rect pos) {
  bounds.left = area.left - pos.width();
  bounds.right = area.right;
  bounds.top = area.top - pos.height();
  bounds.bottom = area.bottom;
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

private void measuredCenterContentStart(String content) {
  Rect rect = new Rect();
  paintCenterText.getTextBounds(content, 0, content.length(), rect);
  switch (gravity) {
    case Gravity.CENTER://显示内容居中
      drawCenterContentStart = (int) ((measuredWidth - rect.width()) * 0.5);
      break;
    case Gravity.LEFT:
      drawCenterContentStart = ConvertUtils.toPx(getContext(), 8);
      break;
    case Gravity.RIGHT://添加偏移量
      drawCenterContentStart = measuredWidth - rect.width() - (int) centerContentOffset;
      break;
  }
}

代码示例来源:origin: naman14/Timber

private BitmapDrawable createFloatingBitmap(View v) {
  floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
  floatingItemBounds = new Rect(floatingItemStatingBounds);
  Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(),
      floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  v.draw(canvas);
  BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
  retDrawable.setBounds(floatingItemBounds);
  return retDrawable;
}

代码示例来源:origin: ankidroid/Anki-Android

public RectangleWrap(Rect rect) {
  super();
  this.x = rect.left;
  this.y = rect.top;
  this.height = rect.height();
  this.width = rect.width();
}

相关文章