本文整理了Java中android.graphics.Rect.centerX
方法的一些代码示例,展示了Rect.centerX
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rect.centerX
方法的具体详情如下:
包路径:android.graphics.Rect
类名称:Rect
方法名:centerX
暂无
代码示例来源:origin: jdsjlzx/LRecyclerView
public int centerX(){
return drawBounds.centerX();
}
代码示例来源:origin: rey5137/material
private float getMaxRadius(float x, float y, Rect bounds){
float x1 = x < bounds.centerX() ? bounds.right : bounds.left;
float y1 = y < bounds.centerY() ? bounds.bottom : bounds.top;
return (float)Math.sqrt(Math.pow(x1 - x, 2) + Math.pow(y1 - y, 2));
}
代码示例来源:origin: ybq/Android-SpinKit
public Rect clipSquare(Rect rect) {
int w = rect.width();
int h = rect.height();
int min = Math.min(w, h);
int cx = rect.centerX();
int cy = rect.centerY();
int r = min / 2;
return new Rect(
cx - r,
cy - r,
cx + r,
cy + r
);
}
代码示例来源:origin: ZieIony/Carbon
private void drawChecked(@NonNull Canvas canvas, float radius) {
Rect bounds = getBounds();
paint.setShader(null);
canvas.drawBitmap(uncheckedBitmap, bounds.left, bounds.top, paint);
maskCanvas.drawColor(0xffffffff);
maskPaint.setXfermode(porterDuffClear);
maskCanvas.drawCircle(maskBitmap.getWidth() / 2 + bounds.width() * offset.x, maskBitmap.getHeight() / 2 + bounds.height() * offset.y, radius, maskPaint);
maskPaint.setXfermode(porterDuffSrcIn);
maskCanvas.drawBitmap(filledBitmap, 0, 0, maskPaint);
canvas.drawBitmap(maskBitmap, bounds.left, bounds.top, paint);
paint.setShader(checkedShader);
canvas.drawCircle(bounds.centerX() + bounds.width() * offset.x, bounds.centerY() + bounds.height() * offset.y, radius, paint);
}
代码示例来源:origin: mikepenz/Android-Iconics
/**
* Set the icon offset
*/
private void offsetIcon(@NonNull Rect viewBounds) {
float startX = viewBounds.centerX() - (mPathBounds.width() / 2);
float offsetX = startX - mPathBounds.left;
float startY = viewBounds.centerY() - (mPathBounds.height() / 2);
float offsetY = startY - (mPathBounds.top);
mPath.offset(offsetX + mIconOffsetX, offsetY + mIconOffsetY);
}
代码示例来源:origin: square/assertj-android
public RectAssert hasCenterX(int center) {
isNotNull();
int actualCenter = actual.centerX();
assertThat(actualCenter) //
.overridingErrorMessage("Expected X center <%s> but was <%s>.", center, actualCenter) //
.isEqualTo(center);
return this;
}
代码示例来源:origin: ybq/Android-SpinKit
@Override
public void drawShape(Canvas canvas, Paint paint) {
if (getDrawBounds() != null) {
paint.setStyle(Paint.Style.STROKE);
int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2;
paint.setStrokeWidth(radius / 12);
canvas.drawCircle(getDrawBounds().centerX(),
getDrawBounds().centerY(),
radius, paint);
}
}
代码示例来源:origin: qiujuer/Genius-Android
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
if (bounds.left == 0 && bounds.top == 0 && bounds.right == 0 && bounds.bottom == 0) {
return;
}
final int centerX = bounds.centerX();
final int centerY = bounds.centerY();
final int radius = Math.min(bounds.height(), bounds.width()) >> 1;
final int maxStrokeRadius = ((int) Math.max(getForegroundLineSize(), getBackgroundLineSize()) >> 1) + 1;
final int areRadius = radius - maxStrokeRadius;
mOval.set(centerX - areRadius, centerY - areRadius, centerX + areRadius, centerY + areRadius);
}
代码示例来源:origin: seven332/EhViewer
@Override
public void draw(Canvas canvas) {
Rect bounds = getBounds();
float canvasRotate;
if (mVerticalMirror) {
canvasRotate = MathUtils.lerp(270, 135f, mProgress);
} else {
canvasRotate = MathUtils.lerp(0f, 135f, mProgress);
}
canvas.save();
canvas.translate(bounds.centerX(), bounds.centerY());
canvas.rotate(canvasRotate);
canvas.drawPath(mPath, mPaint);
canvas.restore();
}
代码示例来源: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: ybq/Android-SpinKit
@Override
public void drawShape(Canvas canvas, Paint paint) {
if (getDrawBounds() != null) {
int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2;
canvas.drawCircle(getDrawBounds().centerX(),
getDrawBounds().centerY(),
radius, paint);
}
}
}
代码示例来源:origin: ybq/Android-SpinKit
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
bounds = clipSquare(bounds);
int radius = (int) (bounds.width() * Math.PI / 3.6f / getChildCount());
int left = bounds.centerX() - radius;
int right = bounds.centerX() + radius;
for (int i = 0; i < getChildCount(); i++) {
Sprite sprite = getChildAt(i);
sprite.setDrawBounds(left, bounds.top, right, bounds.top + radius * 2);
}
}
}
代码示例来源:origin: KeepSafe/TapTargetView
Rect getTextBounds() {
final int totalTextHeight = getTotalTextHeight();
final int totalTextWidth = getTotalTextWidth();
final int possibleTop = targetBounds.centerY() - TARGET_RADIUS - TARGET_PADDING - totalTextHeight;
final int top;
if (possibleTop > topBoundary) {
top = possibleTop;
} else {
top = targetBounds.centerY() + TARGET_RADIUS + TARGET_PADDING;
}
final int relativeCenterDistance = (getWidth() / 2) - targetBounds.centerX();
final int bias = relativeCenterDistance < 0 ? -TEXT_POSITIONING_BIAS : TEXT_POSITIONING_BIAS;
final int left = Math.max(TEXT_PADDING, targetBounds.centerX() - bias - totalTextWidth);
final int right = Math.min(getWidth() - TEXT_PADDING, left + totalTextWidth);
return new Rect(left, top, right, top + totalTextHeight);
}
代码示例来源:origin: ybq/Android-SpinKit
@Override
public void drawChild(Canvas canvas) {
Rect bounds = clipSquare(getBounds());
for (int i = 0; i < getChildCount(); i++) {
int count = canvas.save();
canvas.rotate(45 + i * 90, bounds.centerX(), bounds.centerY());
Sprite sprite = getChildAt(i);
sprite.draw(canvas);
canvas.restoreToCount(count);
}
}
代码示例来源:origin: facebook/litho
public static void clickBottom(LithoView lithoView, String testKey) {
final TestItem testItem = LithoViewTestHelper.findTestItem(lithoView, testKey);
final Rect testItemBounds = testItem.getBounds();
final int[] locationOnScreen = new int[2];
lithoView.getLocationOnScreen(locationOnScreen);
click(new Point(
locationOnScreen[0] + testItemBounds.centerX(),
locationOnScreen[1] + testItemBounds.bottom - 1));
}
代码示例来源:origin: facebook/litho
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
final int cx = bounds.centerX();
final int cy = bounds.centerY();
// Setup points
mP1.set(cx - mWidth, cy - mHeight);
mP2.set(cx + mWidth, cy - mHeight);
mP3.set(cx, cy + mHeight);
// Setup triangle
mTrianglePath.reset();
mTrianglePath.setFillType(Path.FillType.EVEN_ODD);
mTrianglePath.moveTo(mP1.x, mP1.y);
mTrianglePath.lineTo(mP2.x, mP2.y);
mTrianglePath.lineTo(mP3.x, mP3.y);
mTrianglePath.close();
}
代码示例来源:origin: ybq/Android-SpinKit
@Override
public void drawChild(Canvas canvas) {
for (int i = 0; i < getChildCount(); i++) {
Sprite sprite = getChildAt(i);
int count = canvas.save();
canvas.rotate(i * 360 / getChildCount(),
getBounds().centerX(),
getBounds().centerY());
sprite.draw(canvas);
canvas.restoreToCount(count);
}
}
代码示例来源:origin: KeepSafe/TapTargetView
int[] getOuterCircleCenterPoint() {
if (inGutter(targetBounds.centerY())) {
return new int[]{targetBounds.centerX(), targetBounds.centerY()};
}
final int targetRadius = Math.max(targetBounds.width(), targetBounds.height()) / 2 + TARGET_PADDING;
final int totalTextHeight = getTotalTextHeight();
final boolean onTop = targetBounds.centerY() - TARGET_RADIUS - TARGET_PADDING - totalTextHeight > 0;
final int left = Math.min(textBounds.left, targetBounds.left - targetRadius);
final int right = Math.max(textBounds.right, targetBounds.right + targetRadius);
final int titleHeight = titleLayout == null ? 0 : titleLayout.getHeight();
final int centerY = onTop ?
targetBounds.centerY() - TARGET_RADIUS - TARGET_PADDING - totalTextHeight + titleHeight
:
targetBounds.centerY() + TARGET_RADIUS + TARGET_PADDING + titleHeight;
return new int[] { (left + right) / 2, centerY };
}
代码示例来源:origin: ybq/Android-SpinKit
public void setDrawBounds(int left, int top, int right, int bottom) {
this.drawBounds = new Rect(left, top, right, bottom);
setPivotX(getDrawBounds().centerX());
setPivotY(getDrawBounds().centerY());
}
代码示例来源:origin: facebook/litho
public static void click(LithoView lithoView, String testKey) {
final TestItem testItem = LithoViewTestHelper.findTestItem(lithoView, testKey);
if (testItem == null) {
throw new ViewForTestKeyNotFoundException(testKey);
}
final Rect testItemBounds = testItem.getBounds();
final int[] locationOnScreen = new int[2];
lithoView.getLocationOnScreen(locationOnScreen);
click(new Point(
locationOnScreen[0] + testItemBounds.centerX(),
locationOnScreen[1] + testItemBounds.centerY()));
}
内容来源于网络,如有侵权,请联系作者删除!