當前位置: 首頁>>代碼示例>>Java>>正文


Java Path.addRect方法代碼示例

本文整理匯總了Java中android.graphics.Path.addRect方法的典型用法代碼示例。如果您正苦於以下問題:Java Path.addRect方法的具體用法?Java Path.addRect怎麽用?Java Path.addRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.Path的用法示例。


在下文中一共展示了Path.addRect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: booleanTest

import android.graphics.Path; //導入方法依賴的package包/類
private void booleanTest(Canvas canvas) {
        paint.setStyle(Paint.Style.FILL);                   // 設置畫布模式為填充kk
        canvas.translate(mWidth / 2, mHeight / 2);

        Path path1 = new Path();
        Path path2 = new Path();
        Path path3 = new Path();
        Path path4 = new Path();

        path1.addCircle(0, 0, 200, Path.Direction.CW);
        path2.addRect(0, -200, 200, 200, Path.Direction.CW);
        path3.addCircle(0, -100, 100, Path.Direction.CW);
        path4.addCircle(0, 100, 100, Path.Direction.CCW);
//
        path1.op(path2, Path.Op.DIFFERENCE);
        path1.op(path3, Path.Op.UNION);
        path1.op(path4, Path.Op.DIFFERENCE);
        canvas.drawPath(path1, paint);


    }
 
開發者ID:lixiaodaoaaa,項目名稱:ColumnAnimViewProject,代碼行數:22,代碼來源:CanvasTest2View.java

示例2: onDraw

import android.graphics.Path; //導入方法依賴的package包/類
/**
 * Path同樣也給我們封裝好了一些路徑效果,例如圓形,矩形等等,跟canvas.drawXX比較類似,這裏就簡單介紹下
 *
 * addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle)
 * 添加弧線到路徑
 *
 * addCircle(float x, float y, float radius, Path.Direction dir) 添加圓到路徑
 *
 * addOval(float left, float top, float right, float bottom, Path.Direction dir) 添加橢圓到路徑
 *
 * addRect(float left, float top, float right, float bottom, Path.Direction dir) 添加矩形到路徑
 *
 * 上麵的Path.Direction dir參數用來指定繪製時是順時針還是逆時針,Path.Direction.CCW和Path.Direction.CW分別代表逆時針和順時針,
 * 順時針和逆時針主要的作用在於不同的時針方向也就決定了不同的路徑起始點和終點,其他的參數跟canvas.drawXX是一樣的
 */

@Override protected void onDraw(Canvas canvas) {
  //設置繪製風格
  setViewPaint();
  //構建path
  Path path = new Path();
  //添加弧形到path
  path.addArc(100, 100, 300, 300, 0, 270);
  //添加圓形到path
  path.addCircle(200, 500, 100, Path.Direction.CCW);
  //添加矩形到path
  path.addRect(100, 700, 300, 800, Path.Direction.CW);
  //添加橢圓到path
  path.addOval(100, 900, 300, 1000, Path.Direction.CCW);
  //繪製path
  canvas.drawPath(path, paint);
}
 
開發者ID:liuguoquan727,項目名稱:android-study,代碼行數:33,代碼來源:PathOther.java

示例3: onDraw

import android.graphics.Path; //導入方法依賴的package包/類
@Override protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  //無效果
  mEffects[0] = null;
  //拐角處變得圓滑
  mEffects[1] = new CornerPathEffect(30);
  //線段上就會產生許多雜點
  mEffects[2] = new DiscretePathEffect(3.0F, 5.0F);
  //繪製虛線
  mEffects[3] = new DashPathEffect(new float[] { 20, 10, 5, 10 }, 0);
  Path path = new Path();
  path.addRect(0, 0, 8, 8, Path.Direction.CCW);
  //設置點的圖形,即方形點的虛線,圓形點的虛線
  mEffects[4] = new PathDashPathEffect(path, 12, 0, PathDashPathEffect.Style.ROTATE);
  //組合PathEffect
  mEffects[5] = new ComposePathEffect(mEffects[3], mEffects[1]);
  for (int i = 0; i < mEffects.length; i++) {
    mPaint.setPathEffect(mEffects[i]);
    canvas.drawPath(mPath, mPaint);
    canvas.translate(0, 200);
  }
}
 
開發者ID:liuguoquan727,項目名稱:android-study,代碼行數:23,代碼來源:PathEffectView.java

示例4: drawAuxLines

import android.graphics.Path; //導入方法依賴的package包/類
private void drawAuxLines(Canvas canvas) {
    Path path = new Path();

    path.moveTo(B.x, B.y);
    path.addCircle(O.x, O.y, Math.abs(O.x), Path.Direction.CW);
    canvas.drawPath(path, mAuxPaint);

    path.moveTo(O.x, E.y);
    path.lineTo(O.x, F.y);
    path.moveTo(E.x, O.y);
    path.lineTo(F.x, O.y);
    path.addRect(E.x, E.y, F.x, F.y, Path.Direction.CW);
    canvas.drawPath(path, mAuxPaint);

    path.moveTo(O.x, O.y);
    path.lineTo(C.x, C.y);
    canvas.drawPath(path, mAuxPaint);
}
 
開發者ID:brucezz,項目名稱:Jier,代碼行數:19,代碼來源:DrawBoard.java

示例5: testPathDirection

import android.graphics.Path; //導入方法依賴的package包/類
private void testPathDirection(Canvas canvas) {
    canvas.translate(mWidth / 2, mHeight / 2);  // 移動坐標係到屏幕中心

    Path path = new Path();

    path.addRect(-100, -100, 100, 100, Path.Direction.CCW);

    path.setLastPoint(-500, 500);// <-- 重置最後一個點的位置
    path.close();
    canvas.drawPath(path, paint);
    path.close();
}
 
開發者ID:lixiaodaoaaa,項目名稱:ColumnAnimViewProject,代碼行數:13,代碼來源:CanvasTestView.java

示例6: testPathForCan

import android.graphics.Path; //導入方法依賴的package包/類
private void testPathForCan(Canvas canvas) {
        canvas.translate(mWidth / 2, mHeight / 2);  // 移動坐標係到屏幕中心
//        canvas.scale(1, -1);                         // <-- 注意 翻轉y坐標軸

        Path path = new Path();
        Path src = new Path();

        path.addRect(-200, -200, 200, 200, Path.Direction.CW);
        src.addCircle(0, 0, 100, Path.Direction.CW);

        path.addPath(src, 0, 200);
        paint.setColor(Color.BLACK);           // 繪製合並後的路徑
        canvas.drawPath(path, paint);
    }
 
開發者ID:lixiaodaoaaa,項目名稱:ColumnAnimViewProject,代碼行數:15,代碼來源:CanvasTestView.java

示例7: fillTypeTest

import android.graphics.Path; //導入方法依賴的package包/類
private void fillTypeTest(Canvas canvas) {
        paint.setStyle(Paint.Style.FILL);                   // 設置畫布模式為填充kk
        canvas.translate(mWidth / 2, mHeight / 2);          // 移動畫布(坐標係)

        Path path = new Path();                                     // 創建Path

        path.setFillType(Path.FillType.INVERSE_WINDING);                   // 設置Path填充模式為 奇偶規則
//        path.setFillType(Path.FillType.INVERSE_EVEN_ODD);            // 反奇偶規則
        path.addRect(-400, -400, 400, 400, Path.Direction.CW);         // 給Path中添加一個矩形

        canvas.drawPath(path, paint);
    }
 
開發者ID:lixiaodaoaaa,項目名稱:ColumnAnimViewProject,代碼行數:13,代碼來源:CanvasTest2View.java

示例8: clear

import android.graphics.Path; //導入方法依賴的package包/類
/**
 * This method initializes canvas.
 *
 * @return
 */
public void clear() {
  Path path = new Path();
  path.moveTo(0F, 0F);
  path.addRect(0F, 0F, 1000F, 1000F, Path.Direction.CCW);
  path.close();

  Paint paint = new Paint();
  paint.setColor(Color.WHITE);
  paint.setStyle(Paint.Style.FILL);

  if (this.historyPointer == this.pathLists.size()) {
    this.pathLists.add(path);
    this.paintLists.add(paint);
    this.historyPointer++;
  } else {
    // On the way of Undo or Redo
    this.pathLists.set(this.historyPointer, path);
    this.paintLists.set(this.historyPointer, paint);
    this.historyPointer++;

    for (int i = this.historyPointer, size = this.paintLists.size(); i < size; i++) {
      this.pathLists.remove(this.historyPointer);
      this.paintLists.remove(this.historyPointer);
    }
  }

  this.text = "";

  // Clear
  this.invalidate();
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:37,代碼來源:CanvasView.java

示例9: draw

import android.graphics.Path; //導入方法依賴的package包/類
protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
        outlinePaint.setColor(Color.BLACK);
        canvas.drawRect(drawRect, outlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        viewContext.getDrawingRect(viewDrawingRect);

        path.addRect(new RectF(drawRect), Path.Direction.CW);
        outlinePaint.setColor(highlightColor);

        if (isClipPathSupported(canvas)) {
            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, outsidePaint);
        } else {
            drawOutsideFallback(canvas);
        }

        canvas.restore();
        canvas.drawPath(path, outlinePaint);

        if (showThirds) {
            drawThirds(canvas);
        }

        if (showCircle) {
            drawCircle(canvas);
        }

        if (handleMode == HandleMode.Always ||
                (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
            drawHandles(canvas);
        }
    }
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:39,代碼來源:HighlightView.java

示例10: getPath

import android.graphics.Path; //導入方法依賴的package包/類
@Override
protected Path getPath(Canvas canvas, Paint paint) {
  Path path = new Path();
  float x = ParserHelper.fromPercentageToFloat(mX, mCanvasWidth, 0, mScale);
  float y = ParserHelper.fromPercentageToFloat(mY, mCanvasHeight, 0, mScale);
  float w = ParserHelper.fromPercentageToFloat(mW, mCanvasWidth, 0, mScale);
  float h = ParserHelper.fromPercentageToFloat(mH, mCanvasHeight, 0, mScale);
  float rx = ParserHelper.fromPercentageToFloat(mRx, mCanvasWidth, 0, mScale);
  float ry = ParserHelper.fromPercentageToFloat(mRy, mCanvasHeight, 0, mScale);

  if (rx != 0 || ry != 0) {
    if (rx == 0) {
      rx = ry;
    } else if (ry == 0) {
      ry = rx;
    }

    if (rx > w / 2) {
      rx = w / 2;
    }

    if (ry > h / 2) {
      ry = h / 2;
    }
    path.addRoundRect(new RectF(x, y, x + w, y + h), rx, ry, Path.Direction.CW);
  } else {
    path.addRect(x, y, x + w, y + h, Path.Direction.CW);
  }
  return path;
}
 
開發者ID:weex-plugins,項目名稱:weex-svg,代碼行數:31,代碼來源:WXSvgRect.java

示例11: getContentPath

import android.graphics.Path; //導入方法依賴的package包/類
public
@NonNull
Path getContentPath(int viewTopPadding,
                    int viewRightPadding,
                    int viewBottomPadding,
                    int viewLeftPadding,
                    @NonNull RectF contentBox) {
  RectF rectForBorderOutline = new RectF();
  Path contentClip = new Path();
  rectForBorderOutline.set(contentBox);
  if (mBorderRadius != null) {
    prepareBorderRadius();
    float topLeftRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_LEFT_RADIUS);
    float topRightRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_RIGHT_RADIUS);
    float bottomRightRadius = getBorderRadius(mOverlappingBorderRadius,
                                              BORDER_BOTTOM_RIGHT_RADIUS);
    float bottomLeftRadius = getBorderRadius(mOverlappingBorderRadius,
                                             BORDER_BOTTOM_LEFT_RADIUS);
    contentClip.addRoundRect(rectForBorderOutline,
                             new float[]{
                                 topLeftRadius - viewLeftPadding,
                                 topLeftRadius - viewTopPadding,
                                 topRightRadius - viewRightPadding,
                                 topRightRadius - viewTopPadding,
                                 bottomRightRadius - viewRightPadding,
                                 bottomRightRadius - viewBottomPadding,
                                 bottomLeftRadius - viewLeftPadding,
                                 bottomLeftRadius - viewBottomPadding
                             },
                             Path.Direction.CW);
  } else {
    contentClip.addRect(rectForBorderOutline, Path.Direction.CW);
  }
  return contentClip;
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:36,代碼來源:BorderDrawable.java

示例12: prepareBorderPath

import android.graphics.Path; //導入方法依賴的package包/類
private void prepareBorderPath(int topPadding,
                               int rightPadding,
                               int bottomPadding,
                               int leftPadding,
                               @NonNull RectF rectF,
                               @NonNull Path path) {
  if (mBorderRadius != null) {
    prepareBorderRadius(rectF);
    float topLeftRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_LEFT_RADIUS);
    float topRightRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_RIGHT_RADIUS);
    float bottomRightRadius = getBorderRadius(mOverlappingBorderRadius,
                                              BORDER_BOTTOM_RIGHT_RADIUS);
    float bottomLeftRadius = getBorderRadius(mOverlappingBorderRadius,
                                             BORDER_BOTTOM_LEFT_RADIUS);
    path.addRoundRect(
        rectF,
        new float[]{
            topLeftRadius - leftPadding,
            topLeftRadius - topPadding,
            topRightRadius - rightPadding,
            topRightRadius - topPadding,
            bottomRightRadius - rightPadding,
            bottomRightRadius - bottomPadding,
            bottomLeftRadius - leftPadding,
            bottomLeftRadius - bottomPadding
        },
        Path.Direction.CW);
  } else {
    path.addRect(rectF, Path.Direction.CW);
  }
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:32,代碼來源:BorderDrawable.java

示例13: updateBounds

import android.graphics.Path; //導入方法依賴的package包/類
private void updateBounds() {
    final Rect b = getBounds();
    final int width = (int) ((float) b.width() * getLevel() / MAX_LEVEL);
    final float radius = b.height() / 2f;
    mVisibleRect.set(b.left, b.top, b.left + width, b.height());

    // draw round to head of progressbar. I know it looks stupid, don't blame me now.
    mPath = new Path();
    mPath.addRect(b.left, b.top, b.left + width - radius, b.height(), Path.Direction.CCW);
    mPath.addCircle(b.left + width - radius, radius, radius, Path.Direction.CCW);
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:12,代碼來源:ShiftDrawable.java

示例14: drawRepeatBarline

import android.graphics.Path; //導入方法依賴的package包/類
void drawRepeatBarline(Canvas canvas, StaffLayout staffLayout, BarLayout.Barline barline, BarLayout.BarlineLoc loc) {
	final float thick = kThickBarlineThicknessTenths * staffLayout.tenthSize;
	final float thin = kThinBarlineThicknessTenths * staffLayout.tenthSize;
	final float gap = kBarlineSeparationTenths * staffLayout.tenthSize;
	final float dotGap = kRepeatDotsBarlineGap * staffLayout.tenthSize;
	final float dotRadius =  kRepeatDotRadius * staffLayout.tenthSize;
	final float dotOffset = kRepeatDotOffset * staffLayout.tenthSize;
	final float margin = kBarlineBackgroundMargin * staffLayout.tenthSize;

	// construct for repeat double barline - left or right
	Path path = new Path();
	Paint paint = new Paint();
	paint.setARGB(255, 0, 0, 255);
	RectF thickBarline = new RectF(barline.rect.centerX()-thick/2, barline.rect.top, barline.rect.centerX()+thick/2, barline.rect.bottom);
	path.addRect(thickBarline, Path.Direction.CW);
	float thinLeft;
	float dotCentrex;
	if (loc == BarLayout.BarlineLoc.left) {
		thinLeft = thickBarline.right + gap;
		dotCentrex = thinLeft + thin + dotGap + dotRadius;
	} else {
		thinLeft = thickBarline.left - gap - thin;
		dotCentrex = thinLeft - dotGap - dotRadius;
	}
	RectF thinBarline = new RectF(thinLeft, barline.rect.top, thinLeft + thin, barline.rect.bottom);
	path.addRect(thinBarline, Path.Direction.CW);
	// repeat dots on each staff
	for (StaffLayout.Staff staff : staffLayout.staves) {
		float centreStaffY = staff.staffRect.centerY();
		if (centreStaffY + dotOffset < getHeight()) { // ensure we don't add dots below bottom of view height
			path.addCircle(dotCentrex, centreStaffY - dotOffset, dotRadius, Path.Direction.CW);
			path.addCircle(dotCentrex, centreStaffY + dotOffset, dotRadius, Path.Direction.CW);
		}
	}
	// paint translucent white background
	Path bgPath = new Path();
	Paint bgPaint = new Paint();
	bgPaint.setARGB(180, 255, 255, 255);
	// background overlaps foreground by margin
	if (loc == BarLayout.BarlineLoc.left)
		bgPath.addRect(new RectF(thickBarline.left - margin, thickBarline.top-margin, dotCentrex+dotRadius+margin, thickBarline.bottom + margin), Path.Direction.CW);
	else
		bgPath.addRect(new RectF(dotCentrex - dotRadius - margin, thickBarline.top-margin, thickBarline.right + margin, thickBarline.bottom + margin), Path.Direction.CW);
	canvas.drawPath(bgPath, bgPaint);
	// paint repeat double barline in blue
	canvas.drawPath(path, paint);
}
 
開發者ID:joshschriever,項目名稱:LiveNotes,代碼行數:48,代碼來源:SystemView.java

示例15: drawEditFrame

import android.graphics.Path; //導入方法依賴的package包/類
private void drawEditFrame(Canvas canvas) {
    if (!mIsCropEnabled) return;

    if (mCropMode == CropMode.CIRCLE) {
        mPaintTransparent.setFilterBitmap(true);
        mPaintTransparent.setColor(mOverlayColor);
        mPaintTransparent.setStyle(Paint.Style.FILL);

        Path path = new Path();
        path.addRect(mImageRect.left, mImageRect.top, mImageRect.right, mImageRect.bottom, Path.Direction.CW);
        path.addCircle((mFrameRect.left + mFrameRect.right) / 2, (mFrameRect.top + mFrameRect.bottom) / 2, (mFrameRect.right - mFrameRect.left) / 2, Path.Direction.CCW);
        canvas.drawPath(path, mPaintTransparent);

    } else {
        mPaintTransparent.setFilterBitmap(true);
        mPaintTransparent.setColor(mOverlayColor);
        mPaintTransparent.setStyle(Paint.Style.FILL);

        canvas.drawRect(mImageRect.left, mImageRect.top, mImageRect.right, mFrameRect.top, mPaintTransparent);
        canvas.drawRect(mImageRect.left, mFrameRect.bottom, mImageRect.right, mImageRect.bottom, mPaintTransparent);
        canvas.drawRect(mImageRect.left, mFrameRect.top, mFrameRect.left, mFrameRect.bottom, mPaintTransparent);
        canvas.drawRect(mFrameRect.right, mFrameRect.top, mImageRect.right, mFrameRect.bottom, mPaintTransparent);
    }

    mPaintFrame.setAntiAlias(true);
    mPaintFrame.setFilterBitmap(true);
    mPaintFrame.setStyle(Paint.Style.STROKE);
    mPaintFrame.setColor(mFrameColor);
    mPaintFrame.setStrokeWidth(mFrameStrokeWeight);

    canvas.drawRect(mFrameRect.left, mFrameRect.top, mFrameRect.right, mFrameRect.bottom, mPaintFrame);

    if (mShowGuide) {
        mPaintFrame.setColor(mGuideColor);
        mPaintFrame.setStrokeWidth(mGuideStrokeWeight);
        float h1 = mFrameRect.left + (mFrameRect.right - mFrameRect.left) / 3.0f;
        float h2 = mFrameRect.right - (mFrameRect.right - mFrameRect.left) / 3.0f;
        float v1 = mFrameRect.top + (mFrameRect.bottom - mFrameRect.top) / 3.0f;
        float v2 = mFrameRect.bottom - (mFrameRect.bottom - mFrameRect.top) / 3.0f;

        canvas.drawLine(h1, mFrameRect.top, h1, mFrameRect.bottom, mPaintFrame);
        canvas.drawLine(h2, mFrameRect.top, h2, mFrameRect.bottom, mPaintFrame);
        canvas.drawLine(mFrameRect.left, v1, mFrameRect.right, v1, mPaintFrame);
        canvas.drawLine(mFrameRect.left, v2, mFrameRect.right, v2, mPaintFrame);
    }

    if (mShowHandle) {
        mPaintFrame.setStyle(Paint.Style.FILL);
        mPaintFrame.setColor(mHandleColor);
        canvas.drawCircle(mFrameRect.left, mFrameRect.top, mHandleSize, mPaintFrame);
        canvas.drawCircle(mFrameRect.right, mFrameRect.top, mHandleSize, mPaintFrame);
        canvas.drawCircle(mFrameRect.left, mFrameRect.bottom, mHandleSize, mPaintFrame);
        canvas.drawCircle(mFrameRect.right, mFrameRect.bottom, mHandleSize, mPaintFrame);
    }
}
 
開發者ID:liuyanggithub,項目名稱:SuperSelector,代碼行數:56,代碼來源:CropImageView.java


注:本文中的android.graphics.Path.addRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。