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

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

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

Rect.offset介绍

[英]Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.
[中]通过将dx添加到矩形的左、右坐标,并将dy添加到矩形的上、下坐标来偏移矩形。

代码示例

代码示例来源: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: seven332/EhViewer

private void adjustBaseLine(int lineHeight, int startIndex, int endIndex) {
  if (mAlignment == Alignment.TOP)
    return;
  for (int index = startIndex; index < endIndex; index++) {
    final View child = getChildAt(index);
    final MarginLayoutParams lp =
        (MarginLayoutParams)child.getLayoutParams();
    Rect rect = rectList.get(index);
    int offsetRaw = lineHeight - rect.height() - lp.topMargin - lp.bottomMargin;
    if (mAlignment == Alignment.CENTER)
      rect.offset(0, offsetRaw/2);
    else if (mAlignment == Alignment.BOTTOM)
      rect.offset(0, offsetRaw);
  }
}

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

Rect outRect = new Rect();
 int[] location = new int[2];
 private boolean isViewInBounds(View view, int x, int y){
   view.getDrawingRect(outRect);
   view.getLocationOnScreen(location);
   outRect.offset(location[0], location[1]);
   return outRect.contains(x, y);
 }

代码示例来源:origin: binIoter/GuideView

/**
  * Rect在屏幕上去掉状态栏高度的绝对位置
  */
 static Rect getViewAbsRect(View view, int parentX, int parentY) {
  int[] loc = new int[2];
  view.getLocationInWindow(loc);
  Rect rect = new Rect();
  rect.set(loc[0], loc[1], loc[0] + view.getMeasuredWidth(), loc[1] + view.getMeasuredHeight());
  rect.offset(-parentX, -parentY);
  return rect;
 }
}

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

@Override
public void captureEndValues(TransitionValues transitionValues) {
  super.captureEndValues(transitionValues);
  if (!(transitionValues.view instanceof ParallaxScrimageView)) return;
  ParallaxScrimageView psv = ((ParallaxScrimageView) transitionValues.view);
  if (psv.getOffset() == 0) return;
  // as we're going to remove the offset (which drives the parallax) we need to
  // compensate for this by adjusting the target bounds.
  Rect bounds = (Rect) transitionValues.values.get(PROPNAME_BOUNDS);
  bounds.offset(0, psv.getOffset());
  transitionValues.values.put(PROPNAME_BOUNDS, bounds);
}

代码示例来源:origin: andkulikov/Transitions-Everywhere

private void captureValues(@NonNull TransitionValues transitionValues) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
    return;
  }
  View view = transitionValues.view;
  if (view.getWidth() <= 0 || view.getHeight() <= 0) {
    return;
  }
  Rect bounds = new Rect(0, 0, view.getWidth(), view.getHeight());
  if (mFadeBehavior != FADE_BEHAVIOR_REVEAL) {
    bounds.offset(view.getLeft(), view.getTop());
  }
  transitionValues.values.put(PROPNAME_BOUNDS, bounds);
  Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
      Bitmap.Config.ARGB_8888);
  if (view instanceof TextureView) {
    bitmap = ((TextureView) view).getBitmap();
  } else {
    Canvas c = new Canvas(bitmap);
    view.draw(c);
  }
  transitionValues.values.put(PROPNAME_BITMAP, bitmap);
  BitmapDrawable drawable = new BitmapDrawable(view.getResources(), bitmap);
  // TODO: lrtb will be wrong if the view has transXY set
  drawable.setBounds(bounds);
  transitionValues.values.put(PROPNAME_DRAWABLE, drawable);
}

代码示例来源:origin: andkulikov/Transitions-Everywhere

private void captureValues(@NonNull TransitionValues transitionValues) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return;
  }
  View view = transitionValues.view;
  if (view.getWidth() <= 0 || view.getHeight() <= 0) {
    return;
  }
  Rect bounds = new Rect(0, 0, view.getWidth(), view.getHeight());
  if (mFadeBehavior != FADE_BEHAVIOR_REVEAL) {
    bounds.offset(view.getLeft(), view.getTop());
  }
  transitionValues.values.put(PROPNAME_BOUNDS, bounds);
  if (Transition.DBG) {
    Log.d(LOG_TAG, "Captured bounds " + transitionValues.values.get(PROPNAME_BOUNDS));
  }
  Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
      Bitmap.Config.ARGB_8888);
  if (view instanceof TextureView) {
    bitmap = ((TextureView) view).getBitmap();
  } else {
    Canvas c = new Canvas(bitmap);
    view.draw(c);
  }
  transitionValues.values.put(PROPNAME_BITMAP, bitmap);
  BitmapDrawable drawable = new BitmapDrawable(view.getResources(), bitmap);
  // TODO: lrtb will be wrong if the view has transXY set
  drawable.setBounds(bounds);
  transitionValues.values.put(PROPNAME_DRAWABLE, drawable);
}

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

private void calculateFrames() {
  if (containerSize == null || previewSize == null || displayConfiguration == null) {
    previewFramingRect = null;
    framingRect = null;
    surfaceRect = null;
    throw new IllegalStateException("containerSize or previewSize is not set yet");
  }
  int previewWidth = previewSize.width;
  int previewHeight = previewSize.height;
  int width = containerSize.width;
  int height = containerSize.height;
  surfaceRect = displayConfiguration.scalePreview(previewSize);
  Rect container = new Rect(0, 0, width, height);
  framingRect = calculateFramingRect(container, surfaceRect);
  Rect frameInPreview = new Rect(framingRect);
  frameInPreview.offset(-surfaceRect.left, -surfaceRect.top);
  previewFramingRect = new Rect(frameInPreview.left * previewWidth / surfaceRect.width(),
      frameInPreview.top * previewHeight / surfaceRect.height(),
      frameInPreview.right * previewWidth / surfaceRect.width(),
      frameInPreview.bottom * previewHeight / surfaceRect.height());
  if (previewFramingRect.width() <= 0 || previewFramingRect.height() <= 0) {
    previewFramingRect = null;
    framingRect = null;
    Log.w(TAG, "Preview frame is too small");
  } else {
    fireState.previewSized();
  }
}

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

tile.fileSRect.offset(view.sRegion.left, view.sRegion.top);

代码示例来源:origin: UFreedom/FloatingView

int[] location = new int[2];
mFloatingDecorView.getLocationOnScreen(location);
rect.offset(-location[0], -location[1]);

代码示例来源: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: ZieIony/Carbon

void drawViewGroup(Canvas canvas, ViewGroup viewGroup) {
    drawView(canvas, viewGroup);
    canvas.save();
    int[] l = new int[2];
    viewGroup.getLocationOnScreen(l);
    rect.set(0, 0, viewGroup.getWidth(), viewGroup.getHeight());
    rect.offset(l[0] - location[0], l[1] - location[1]);
    canvas.clipRect(rect);
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
      View v = viewGroup.getChildAt(i);
      if (v instanceof ViewGroup) {
        drawViewGroup(canvas, (ViewGroup) v);
      } else {
        drawView(canvas, v);
      }
    }
    canvas.restore();
  }
}

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

);
if (sRegion != null) {
  fRect.offset(sRegion.left, sRegion.top);

代码示例来源:origin: ZieIony/Carbon

private void drawView(Canvas canvas, View v) {
  int[] l = new int[2];
  v.getLocationOnScreen(l);
  rect.set(0, 0, v.getWidth(), v.getHeight());
  rect.offset(l[0] - location[0], l[1] - location[1]);
  if (drawMargins)
    drawMargins(canvas, v);
  if (drawPaddings)
    drawPaddings(canvas, v);
  if (drawBounds)
    drawBounds(canvas, v);
  if (drawHitRects) {
    v.getHitRect(rect2);
    rect2.offset(l[0] - location[0] - v.getLeft(), l[1] - location[1] - v.getTop());
    if (!rect.equals(rect2)) {
      paint.setColor(0x7fff0000);
      canvas.drawRect(rect2, paint);
    }
  }
  if (drawTextSizes && v instanceof TextView) {
    TextView tv = (TextView) v;
    paint.setTextSize(12);
    float textSize = tv.getTextSize() / getResources().getDisplayMetrics().scaledDensity;
    paint.setColor(Color.WHITE);
    paint.setShadowLayer(2, 0, 0, 0xff000000);
    canvas.drawText(textSize + "sp", rect.left, rect.top + paint.getTextSize(), paint);
  }
}

代码示例来源:origin: robolectric/robolectric

@Implementation
protected boolean getGlobalVisibleRect(Rect rect, Point globalOffset) {
 if (globalVisibleRect == null) {
  return directly().getGlobalVisibleRect(rect, globalOffset);
 }
 if (!globalVisibleRect.isEmpty()) {
  rect.set(globalVisibleRect);
  if (globalOffset != null) {
   rect.offset(-globalOffset.x, -globalOffset.y);
  }
  return true;
 }
 rect.setEmpty();
 return false;
}

代码示例来源:origin: robolectric/robolectric

@Test
 public void offsetModifiesRect() {
  Rect r = new Rect(1, 2, 3, 4);
  r.offset(10, 20);
  assertThat(r.left).isEqualTo(11);
  assertThat(r.top).isEqualTo(22);
  assertThat(r.right).isEqualTo(13);
  assertThat(r.bottom).isEqualTo(24);
 }
}

代码示例来源:origin: Dimezis/BlurView

/**
 * setup matrix to draw starting from blurView's position
 */
private void setupInternalCanvasMatrix() {
  blurView.getDrawingRect(relativeViewBounds);
  if (shouldTryToOffsetCoords) {
    try {
      rootView.offsetDescendantRectToMyCoords(blurView, relativeViewBounds);
    } catch (IllegalArgumentException e) {
      // BlurView is not a child of the rootView (i.e. it's in Dialog)
      // Fallback to regular coordinates system
      shouldTryToOffsetCoords = false;
    }
  } else {
    blurView.getLocationInWindow(locationInWindow);
    relativeViewBounds.offset(locationInWindow[0], locationInWindow[1]);
  }
  float scaleFactorX = scaleFactor * roundingWidthScaleFactor;
  float scaleFactorY = scaleFactor * roundingHeightScaleFactor;
  float scaledLeftPosition = -relativeViewBounds.left / scaleFactorX;
  float scaledTopPosition = -relativeViewBounds.top / scaleFactorY;
  float scaledTranslationX = blurView.getTranslationX() / scaleFactorX;
  float scaledTranslationY = blurView.getTranslationY() / scaleFactorY;
  internalCanvas.translate(scaledLeftPosition - scaledTranslationX, scaledTopPosition - scaledTranslationY);
  internalCanvas.scale(1f / scaleFactorX, 1f / scaleFactorY);
}

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

/** @return bounds for a given LayoutOutput within its actual host, {@see getActualHostMarker} */
private static void getActualBounds(
  LayoutOutput layoutOutput, LayoutState layoutState, BitSet skipMounting, Rect outRect) {
 final long actualHostMarker = getActualHostMarker(layoutOutput, layoutState, skipMounting);
 layoutOutput.getMountBounds(outRect);
 long hostMarker = layoutOutput.getHostMarker();
 while (hostMarker != actualHostMarker) {
  final LayoutOutput ancestor = layoutState.getLayoutOutput(hostMarker);
  ancestor.getMountBounds(sTempRect2);
  outRect.offset(sTempRect2.left, sTempRect2.top);
  hostMarker = ancestor.getHostMarker();
 }
}

代码示例来源:origin: ZieIony/Carbon

for (int i = 0; i < N; i++) {
  activeRipples[i].getBounds(rippleBounds);
  rippleBounds.offset(cX, cY);
  drawingBounds.union(rippleBounds);
if (background != null) {
  background.getBounds(rippleBounds);
  rippleBounds.offset(cX, cY);
  drawingBounds.union(rippleBounds);

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

bounds.offset(offsetX, offsetY);
displayListDrawable.setBounds(bounds);

相关文章