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

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

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

Rect.offsetTo介绍

[英]Offset the rectangle to a specific (left, top) position, keeping its width and height the same.
[中]将矩形偏移到特定(左、上)位置,保持其宽度和高度相同。

代码示例

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

@Override
public void set(@NonNull Drawable object, @NonNull PointF value) {
  object.copyBounds(mBounds);
  mBounds.offsetTo(Math.round(value.x), Math.round(value.y));
  object.setBounds(mBounds);
}

代码示例来源:origin: scwang90/SmartRefreshLayout

bounds1.offsetTo(width / 2 - bounds1.width() / 2, (int)((body.boxCenterY - bounds1.height() / 2 + bounds1.height()) * percent1) - bounds1.height());
mDrawable1.draw(canvas);
bounds2.offsetTo(width / 2 - bounds2.width() / 2, (int)((body.boxCenterY - bounds2.height() / 2 + bounds2.height()) * percent2) - bounds2.height());
mDrawable2.draw(canvas);
bounds3.offsetTo(width / 2 - bounds3.width() / 2, (int) ((body.boxCenterY - bounds3.height() / 2 + bounds3.height()) * percent3) - bounds3.height());
mDrawable3.draw(canvas);
  bounds1.offsetTo(width / 2 - bounds1.width() / 2, ((body.boxCenterY - bounds1.height() / 2)));
  mDrawable1.draw(canvas);
  bounds2.offsetTo(width / 2 - bounds2.width() / 2, ((body.boxCenterY - bounds2.height() / 2)));
  mDrawable2.draw(canvas);
  bounds3.offsetTo(width / 2 - bounds3.width() / 2, ((body.boxCenterY - bounds3.height() / 2)));
  mDrawable3.draw(canvas);

代码示例来源:origin: scwang90/SmartRefreshLayout

mCloudDrawable.getBounds().offsetTo(mCloudX1, mHeaderHeight / 3);
  mCloudDrawable.draw(canvas);
  mCloudDrawable.getBounds().offsetTo(mCloudX2, mHeaderHeight / 2);
  mCloudDrawable.draw(canvas);
  mCloudDrawable.getBounds().offsetTo(mCloudX3, mHeaderHeight * 2 / 3);
  mCloudDrawable.draw(canvas);
  canvas.rotate(5 * (float) Math.sin(mAppreciation / 2), width / 2 , mHeaderHeight / 2 - mUmbrellaDrawable.getBounds().height());
final int centerYBox = centerY + (mHeaderHeight / 2 - mBoxDrawable.getBounds().height())
    - Math.min(mHeaderHeight / 2 - mBoxDrawable.getBounds().height(), DensityUtil.dp2px(mAppreciation * 100));
mBoxDrawable.getBounds().offsetTo(width / 2 - mBoxDrawable.getBounds().width() / 2, centerYBox - mBoxDrawable.getBounds().height() / 4);
mBoxDrawable.draw(canvas);
  Rect bounds = mUmbrellaDrawable.getBounds();
  final int centerYUmbrella = centerY - mHeaderHeight + Math.min(mHeaderHeight, DensityUtil.dp2px(mAppreciation * 100));
  mUmbrellaDrawable.getBounds().offsetTo(width / 2 - bounds.width() / 2, centerYUmbrella - bounds.height());
  mUmbrellaDrawable.draw(canvas);

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

@Override
public Animator onDisappear(@NonNull ViewGroup sceneRoot, @NonNull View view,
              @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) {
  if (startValues == null) {
    return null;
  }
  Rect bounds = (Rect) startValues.values.get(PROPNAME_SCREEN_BOUNDS);
  int viewPosX = bounds.left;
  int viewPosY = bounds.top;
  float startX = view.getTranslationX();
  float startY = view.getTranslationY();
  float endX = startX;
  float endY = startY;
  int[] interruptedPosition = (int[]) startValues.view.getTag(R.id.transitionPosition);
  if (interruptedPosition != null) {
    // We want to have the end position relative to the interrupted position, not
    // the position it was supposed to start at.
    endX += interruptedPosition[0] - bounds.left;
    endY += interruptedPosition[1] - bounds.top;
    bounds.offsetTo(interruptedPosition[0], interruptedPosition[1]);
  }
  calculateOut(sceneRoot, bounds, mTempLoc);
  endX += mTempLoc[0];
  endY += mTempLoc[1];
  return TranslationAnimationCreator.createAnimation(view, startValues,
      viewPosX, viewPosY, startX, startY, endX, endY, sAccelerate, this);
}

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

public void draw(Canvas canvas) {
  if (isVisible()) {
    // Draw the fast scroller popup
    int restoreCount = canvas.save();
    canvas.translate(mBgBounds.left, mBgBounds.top);
    mTmpRect.set(mBgBounds);
    mTmpRect.offsetTo(0, 0);
    mBackgroundPath.reset();
    mBackgroundRect.set(mTmpRect);
    float[] radii = createRadii();
    mBackgroundPath.addRoundRect(mBackgroundRect, radii, Path.Direction.CW);
    mBackgroundPaint.setAlpha((int) (Color.alpha(mBackgroundColor) * mAlpha));
    mTextPaint.setAlpha((int) (mAlpha * 255));
    canvas.drawPath(mBackgroundPath, mBackgroundPaint);
    canvas.drawText(mSectionName, (mBgBounds.width() - mTextBounds.width()) / 2,
        mBgBounds.height() - (mBgBounds.height() - mTextBounds.height()) / 2,
        mTextPaint);
    canvas.restoreToCount(restoreCount);
  }
}

代码示例来源:origin: elevenetc/InteractiveCanvas

public void setPosition(int x, int y) {
  bounds.offsetTo(x, y);
}

代码示例来源:origin: elevenetc/InteractiveCanvas

public void onDrag(int y) {
  bounds.offsetTo(bounds.left, startDragTop + y - downY);
}

代码示例来源:origin: enricocid/LaunchEnr

protected static Rect getDrawableBounds(Drawable d) {
  Rect bounds = new Rect();
  d.copyBounds(bounds);
  if (bounds.width() == 0 || bounds.height() == 0) {
    bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
  } else {
    bounds.offsetTo(0, 0);
  }
  return bounds;
}

代码示例来源:origin: czy1121/badgebutton

void layout(int x, int y, int max) {
  Rect rect = getBounds();
  rect.offsetTo(Math.min(x - rect.width() / 2, max - rect.width() - (int)(0.2f * mHeight)), Math.max(0, y - rect.height() / 2));
  setBounds(rect);
}

代码示例来源:origin: redfish64/TinyTravelTracker

public void drawBubble(Canvas canvas, String text, int x, int y) {
  
  Rect bounds = new Rect();
  textPaint.getTextBounds(text, 0, text.length(), bounds);
  bounds.offsetTo(0, 0);
  
  Point point = speechBubbleDrawer.getPointLocationGivenInner(bounds);
  
  bounds.offsetTo(x - point.x, y - point.y);
  
  speechBubbleDrawer.draw(canvas, bounds.left, bounds.top, bounds.width(), bounds.height());
  canvas.drawText(text, bounds.left, bounds.top - fontMetrics.ascent, textPaint);
}

代码示例来源:origin: redfish64/TinyTravelTracker

public void getClickableArea(Rect result, View view, String text, int x, int y) {
  textPaint.getTextBounds(text, 0, text.length(), result);
  result.offsetTo(0, 0);
  
  Point point = speechBubbleDrawer.getPointLocationGivenInner(result);
  
  result.offsetTo(x - point.x, y - point.y);
  
  speechBubbleDrawer.updateInnerRectForClickableArea(result);
}

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

private static Rect getDrawableBounds(Drawable d) {
  Rect bounds = new Rect();
  d.copyBounds(bounds);
  if (bounds.width() == 0 || bounds.height() == 0) {
    bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
  } else {
    bounds.offsetTo(0, 0);
  }
  if (d instanceof PreloadIconDrawable) {
    int inset = -((PreloadIconDrawable) d).getOutset();
    bounds.inset(inset, inset);
  }
  return bounds;
}

代码示例来源:origin: edx/edx-app-android

@Override
protected void onBoundsChange(@NonNull Rect bounds) {
  final int width = bounds.width();
  final int height = bounds.height();
  paint.setTextSize(height);
  paint.getTextBounds(text, 0, 1, drawBounds);
  paint.setTextSize(Math.min(height, (int) Math.ceil(
      width * (height / (float) drawBounds.width()))));
  paint.getTextBounds(text, 0, 1, drawBounds);
  drawBounds.offsetTo(bounds.left + (width - drawBounds.width()) / 2,
      bounds.top + (height - drawBounds.height()) / 2 - drawBounds.bottom);
  centerX = bounds.exactCenterX();
  centerY = bounds.exactCenterY();
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

protected static Rect getDrawableBounds(Drawable d) {
  Rect bounds = new Rect();
  d.copyBounds(bounds);
  if (bounds.width() == 0 || bounds.height() == 0) {
    bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
  } else {
    bounds.offsetTo(0, 0);
  }
  if (d instanceof PreloadIconDrawable) {
    int inset = -((PreloadIconDrawable) d).getOutset();
    bounds.inset(inset, inset);
  }
  return bounds;
}

代码示例来源:origin: iSpring/GamePlane

@Override
public Rect getBitmapSrcRec() {
  Rect rect = super.getBitmapSrcRec();
  int left = (int)(level * getWidth());
  rect.offsetTo(left, 0);
  return rect;
}

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

@Override
public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
  super.getHitRect(outRect);
  outRect.bottom += mBottomDragPadding;
  int[] coords = new int[2];
  mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, coords);
  outRect.offsetTo(coords[0], coords[1]);
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

@Override
public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
  super.getHitRect(outRect);
  outRect.bottom += mBottomDragPadding;
  int[] coords = new int[2];
  mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, coords);
  outRect.offsetTo(coords[0], coords[1]);
}

代码示例来源:origin: klinker24/launcher3

@Override
public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
  super.getHitRect(outRect);
  outRect.bottom += mBottomDragPadding;
  int[] coords = new int[2];
  mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, coords);
  outRect.offsetTo(coords[0], coords[1]);
}

代码示例来源:origin: enricocid/LaunchEnr

@Override
public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
  super.getHitRect(outRect);
  outRect.bottom += mBottomDragPadding;
  int[] coords = new int[2];
  mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, coords);
  outRect.offsetTo(coords[0], coords[1]);
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

@Override
public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
  super.getHitRect(outRect);
  outRect.bottom += mBottomDragPadding;
  int[] coords = new int[2];
  mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, coords);
  outRect.offsetTo(coords[0], coords[1]);
}

相关文章