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

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

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

Rect.inset介绍

[英]Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards, making the rectangle narrower. If dx is negative, then the sides are moved outwards, making the rectangle wider. The same holds true for dy and the top and bottom.
[中]按(dx,dy)插入矩形。如果dx为正,则两侧向内移动,使矩形变窄。如果dx为负,则边向外移动,使矩形变宽。dy、顶部和底部也是如此。

代码示例

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

Rect newRect = canvas.getClipBounds();
newRect.inset(-5, -5)  //make the rect larger

canvas.clipRect (newRect, Region.Op.REPLACE);
//happily draw outside the bound now

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

void init(View delegateView, Rect delegateBounds) {
 mDelegateView = delegateView;
 mSlop = ViewConfiguration.get(delegateView.getContext()).getScaledTouchSlop();
 mDelegateBounds.set(delegateBounds);
 mDelegateSlopBounds.set(delegateBounds);
 mDelegateSlopBounds.inset(-mSlop, -mSlop);
}

代码示例来源:origin: journeyapps/zxing-android-embedded

intersection.inset(horizontalMargin, verticalMargin);
  return intersection;
intersection.inset(margin, margin);
if (intersection.height() > intersection.width()) {
  intersection.inset(0, (intersection.height() - intersection.width()) / 2);

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

@Override
 public void draw(Canvas canvas) {
  // We don't have access to the OverlayViewGroup instance directly, but we can manipulate
  // its Canvas via the Drawables' draw(). This allows us to draw outside the View bounds,
  // so we can position the margin overlays correctly.
  Rect newRect = canvas.getClipBounds();
  // Make the Canvas Rect bigger according to the View margins.
  newRect.inset(-(mMargins.right + mMargins.left), -(mMargins.top + mMargins.bottom));
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
   canvas.clipRect(newRect, Region.Op.REPLACE);
  } else {
   canvas.clipOutRect(newRect);
  }
  super.draw(canvas);
 }
}

代码示例来源:origin: xfumihiro/ViewInspector

int dx = -Math.max(mlp.leftMargin, mlp.rightMargin);
int dy = -Math.max(mlp.topMargin, mlp.bottomMargin);
newRect.inset(dx, dy);
canvas.clipRect(newRect, Region.Op.REPLACE);

代码示例来源:origin: jdamcd/android-crop

void moveBy(float dx, float dy) {
  Rect invalRect = new Rect(drawRect);
  cropRect.offset(dx, dy);
  // Put the cropping rectangle inside image rectangle
  cropRect.offset(
      Math.max(0, imageRect.left - cropRect.left),
      Math.max(0, imageRect.top  - cropRect.top));
  cropRect.offset(
      Math.min(0, imageRect.right  - cropRect.right),
      Math.min(0, imageRect.bottom - cropRect.bottom));
  drawRect = computeLayout();
  invalRect.union(drawRect);
  invalRect.inset(-(int) handleRadius, -(int) handleRadius);
  viewContext.invalidate(invalRect);
}

代码示例来源:origin: KeepSafe/TapTargetView

int getOuterCircleRadius(int centerX, int centerY, Rect textBounds, Rect targetBounds) {
 final int targetCenterX = targetBounds.centerX();
 final int targetCenterY = targetBounds.centerY();
 final int expandedRadius = (int) (1.1f * TARGET_RADIUS);
 final Rect expandedBounds = new Rect(targetCenterX, targetCenterY, targetCenterX, targetCenterY);
 expandedBounds.inset(-expandedRadius, -expandedRadius);
 final int textRadius = maxDistanceToPoints(centerX, centerY, textBounds);
 final int targetRadius = maxDistanceToPoints(centerX, centerY, expandedBounds);
 return Math.max(textRadius, targetRadius) + CIRCLE_PADDING;
}

代码示例来源:origin: tyrantgit/ExplosionField

public void explode(final View view) {
  Rect r = new Rect();
  view.getGlobalVisibleRect(r);
  int[] location = new int[2];
  getLocationOnScreen(location);
  r.offset(-location[0], -location[1]);
  r.inset(-mExpandInset[0], -mExpandInset[1]);
  int startDelay = 100;
  ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150);
  animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    Random random = new Random();
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
      view.setTranslationX((random.nextFloat() - 0.5f) * view.getWidth() * 0.05f);
      view.setTranslationY((random.nextFloat() - 0.5f) * view.getHeight() * 0.05f);
    }
  });
  animator.start();
  view.animate().setDuration(150).setStartDelay(startDelay).scaleX(0f).scaleY(0f).alpha(0f).start();
  explode(Utils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION);
}

代码示例来源:origin: timusus/RecyclerView-FastScroll

/**
 * Returns whether the specified points are near the scroll bar bounds.
 */
private boolean isNearPoint(int x, int y) {
  mTmpRect.set(mThumbPosition.x, mThumbPosition.y, mThumbPosition.x + mWidth,
      mThumbPosition.y + mThumbHeight);
  mTmpRect.inset(mTouchInset, mTouchInset);
  return mTmpRect.contains(x, y);
}

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

croppedImage = Bitmap.createBitmap(mOutputX, mOutputY, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(croppedImage);

Rect srcRect = mCrop.getCropRect();
Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);

int dx = (srcRect.width() - dstRect.width()) / 2;
int dy = (srcRect.height() - dstRect.height()) / 2;

// If the srcRect is too big, use the center part of it.
srcRect.inset(Math.max(0, dx), Math.max(0, dy));

// If the dstRect is too big, use the center part of it.
dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));

// Draw the cropped bitmap in the center
canvas.drawBitmap(mBitmap, srcRect, dstRect, null);

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

expandedBounds.inset(-FLING_MARGIN, -FLING_MARGIN);

代码示例来源:origin: multidots/android-app-common-tasks

private void moveBy(float dx, float dy) {
  Rect invalRect = new Rect(mDrawRect);
  mCropRect.offset(dx, dy);
  // Put the cropping rectangle inside image rectangle.
  mCropRect.offset(
      Math.max(0, mImageRect.left - mCropRect.left),
      Math.max(0, mImageRect.top - mCropRect.top));
  mCropRect.offset(
      Math.min(0, mImageRect.right - mCropRect.right),
      Math.min(0, mImageRect.bottom - mCropRect.bottom));
  mDrawRect = computeLayout();
  invalRect.union(mDrawRect);
  invalRect.inset(-10, -10);
  mContext.invalidate(invalRect);
}

代码示例来源:origin: multidots/android-app-common-tasks

private void moveBy(float dx, float dy) {
  Rect invalRect = new Rect(mDrawRect);
  mCropRect.offset(dx, dy);
  // Put the cropping rectangle inside image rectangle.
  mCropRect.offset(
      Math.max(0, mImageRect.left - mCropRect.left),
      Math.max(0, mImageRect.top - mCropRect.top));
  mCropRect.offset(
      Math.min(0, mImageRect.right - mCropRect.right),
      Math.min(0, mImageRect.bottom - mCropRect.bottom));
  mDrawRect = computeLayout();
  invalRect.union(mDrawRect);
  invalRect.inset(-10, -10);
  mContext.invalidate(invalRect);
}

代码示例来源:origin: multidots/android-app-common-tasks

srcRect.inset(Math.max(0, dx), Math.max(0, dy));
dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));

代码示例来源:origin: multidots/android-app-common-tasks

srcRect.inset(Math.max(0, dx), Math.max(0, dy));
dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));

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

bounds.inset(mPadding, mPadding);

代码示例来源:origin: BiglySoftware/BiglyBT-Android

/**
 * Returns whether the specified points are near the scroll bar bounds.
 */
private boolean isNearPoint(int x, int y) {
  mTmpRect.set(mThumbPosition.x, mThumbPosition.y, mThumbPosition.x + mWidth,
      mThumbPosition.y + mThumbHeight);
  mTmpRect.inset(mTouchInset, mTouchInset);
  return mTmpRect.contains(x, y);
}

代码示例来源:origin: fookwood/Launcher3

/**
   * Returns whether the specified points are near the scroll bar bounds.
   */
  private boolean isNearThumb(int x, int y) {
    mTmpRect.set(mThumbOffset.x, mThumbOffset.y, mThumbOffset.x + mThumbWidth,
        mThumbOffset.y + mThumbHeight);
    mTmpRect.inset(mTouchInset, mTouchInset);
    return mTmpRect.contains(x, y);
  }
}

代码示例来源:origin: fookwood/Launcher3

@Override
protected void onBoundsChange(Rect bounds) {
  mIcon.setBounds(bounds);
  if (mBgDrawable != null) {
    sTempRect.set(bounds);
    sTempRect.inset(-mRingOutset, -mRingOutset);
    mBgDrawable.setBounds(sTempRect);
  }
  mIndicatorRectDirty = true;
}

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

private final Rect mBounds = new Rect();
private final Date mDate = new Date();

private void measureText(final Paint p){
  final String dummy =  DateFormat.getDateTimeInstance().format(mDate);
  p.getTextBounds(dummy, 0, dummy.length(), mBounds);
  final int inset = (int) (mBounds.width()*0.1f); //add safety margin
  mBounds.inset(-inset, 0);
}

相关文章