android.graphics.Path.lineTo()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(132)

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

Path.lineTo介绍

暂无

代码示例

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

@NonNull
private Path generateClipPath(BoxBody body, int width) {
  mPath.reset();
  mPath.lineTo(0, body.boxCenterTop);
  mPath.lineTo(body.boxLeft, body.boxCenterTop);
  mPath.lineTo(body.boxCenterX, body.boxCenterY);
  mPath.lineTo(body.boxRight, body.boxCenterTop);
  mPath.lineTo(width, body.boxCenterTop);
  mPath.lineTo(width, 0);
  mPath.close();
  return mPath;
}

代码示例来源:origin: square/picasso

private static Path getTrianglePath(int x1, int y1, int width) {
  final Path path = new Path();
  path.moveTo(x1, y1);
  path.lineTo(x1 + width, y1);
  path.lineTo(x1, y1 + width);

  return path;
 }
}

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

protected void drawWave(Canvas canvas, int width) {
  //重置画笔
  mPath.reset();
  //绘制贝塞尔曲线
  mPath.lineTo(0, mWaveTop);
  mPath.quadTo(mWaveOffsetX >= 0 ? (mWaveOffsetX) : width / 2, mWaveTop + mWaveHeight, width, mWaveTop);
  mPath.lineTo(width, 0);
  mPaint.setColor(mPrimaryColor);
  canvas.drawPath(mPath, mPaint);
}

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

@NonNull
private Path generateBoxBodyPath(BoxBody body) {
  mPath.reset();
  mPath.moveTo(body.boxLeft, body.boxCenterBottom);
  mPath.lineTo(body.boxCenterX, body.boxBottom);
  mPath.lineTo(body.boxRight, body.boxCenterBottom);
  mPath.quadTo(body.boxRight + body.boxSideLength / 2 * mReboundPercent, body.boxCenterY, body.boxRight, body.boxCenterTop);
  mPath.lineTo(body.boxCenterX, body.boxTop);
  mPath.lineTo(body.boxLeft, body.boxCenterTop);
  mPath.quadTo(body.boxLeft - body.boxSideLength / 2 * mReboundPercent, body.boxCenterY, body.boxLeft, body.boxCenterBottom);
  mPath.close();
  return mPath;
}
//</editor-fold>

代码示例来源:origin: square/leakcanary

private static void squigglyHorizontalPath(Path path, float left, float right, float centerY,
   float amplitude,
   float periodDegrees) {
  path.reset();

  float y;
  path.moveTo(left, centerY);
  float period = (float) (2 * Math.PI / periodDegrees);

  for (float x = 0; x <= right - left; x += 1) {
   y = (float) (amplitude * Math.sin(40 + period * x) + centerY);
   path.lineTo(left + x, y);
  }
 }
}

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

private void drawWave(Canvas canvas, int viewWidth, int viewHeight) {
  float baseHeight = Math.min(mHeadHeight, viewHeight);
  if (mWaveHeight != 0) {
    mPath.reset();
    mPath.lineTo(viewWidth, 0);
    mPath.lineTo(viewWidth, baseHeight);
    mPath.quadTo(viewWidth / 2, baseHeight + mWaveHeight * 2, 0, baseHeight);
    mPath.close();
    canvas.drawPath(mPath, mBackPaint);
  } else {
    canvas.drawRect(0, 0, viewWidth, baseHeight, mBackPaint);
  }
}

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

private void drawBollTail(Canvas canvas, int viewWidth, float fraction) {
  if (mShowBollTail) {
    final float bottom = mHeadHeight + mWaveHeight;
    final float startY = mBollY + mBollRadius * fraction / 2;
    final float startX = viewWidth / 2 + (float) Math.sqrt(mBollRadius * mBollRadius * (1 - fraction * fraction / 4));
    final float bezier1x = (viewWidth / 2 + (mBollRadius * 3 / 4) * (1 - fraction));
    final float bezier2x = bezier1x + mBollRadius;
    mPath.reset();
    mPath.moveTo(startX, startY);
    mPath.quadTo(bezier1x, bottom, bezier2x, bottom);
    mPath.lineTo(viewWidth - bezier2x, bottom);
    mPath.quadTo(viewWidth - bezier1x, bottom, viewWidth - startX, startY);
    canvas.drawPath(mPath, mFrontPaint);
  }
}

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

@Override
protected void dispatchDraw(Canvas canvas) {
  if (mShowBezierWave) {
    //重置画笔
    mBezierPath.reset();
    mBezierPath.lineTo(0, mHeadHeight);
    //绘制贝塞尔曲线
    final View thisView = this;
    mBezierPath.quadTo(thisView.getMeasuredWidth() / 2, mHeadHeight + mWaveHeight * 1.9f, thisView.getMeasuredWidth(), mHeadHeight);
    mBezierPath.lineTo(thisView.getMeasuredWidth(), 0);
    canvas.drawPath(mBezierPath, mBezierPaint);
  }
  super.dispatchDraw(canvas);
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
protected void drawGridLine(Canvas c, float x, float y, Path gridLinePath) {
  gridLinePath.moveTo(mViewPortHandler.contentRight(), y);
  gridLinePath.lineTo(mViewPortHandler.contentLeft(), y);
  // draw a path because lines don't support dashing on lower android versions
  c.drawPath(gridLinePath, mGridPaint);
  gridLinePath.reset();
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
protected Path linePath(Path p, int i, float[] positions) {
  p.moveTo(positions[i], mViewPortHandler.contentTop());
  p.lineTo(positions[i], mViewPortHandler.contentBottom());
  return p;
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Draws the grid line at the specified position using the provided path.
 *
 * @param c
 * @param x
 * @param y
 * @param gridLinePath
 */
protected void drawGridLine(Canvas c, float x, float y, Path gridLinePath) {
  gridLinePath.moveTo(x, mViewPortHandler.contentBottom());
  gridLinePath.lineTo(x, mViewPortHandler.contentTop());
  // draw a path because lines don't support dashing on lower android versions
  c.drawPath(gridLinePath, mGridPaint);
  gridLinePath.reset();
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Calculates the path for a grid line.
 *
 * @param p
 * @param i
 * @param positions
 * @return
 */
protected Path linePath(Path p, int i, float[] positions) {
  p.moveTo(mViewPortHandler.offsetLeft(), positions[i + 1]);
  p.lineTo(mViewPortHandler.contentRight(), positions[i + 1]);
  return p;
}

代码示例来源:origin: airbnb/lottie-android

public static Path createPath(PointF startPoint, PointF endPoint, PointF cp1, PointF cp2) {
 Path path = new Path();
 path.moveTo(startPoint.x, startPoint.y);
 if (cp1 != null  && cp2 != null && (cp1.length() != 0 || cp2.length() != 0)) {
  path.cubicTo(
    startPoint.x + cp1.x, startPoint.y + cp1.y,
    endPoint.x + cp2.x, endPoint.y + cp2.y,
    endPoint.x, endPoint.y);
 } else {
  path.lineTo(endPoint.x, endPoint.y);
 }
 return path;
}

代码示例来源:origin: PhilJay/MPAndroidChart

public void renderLimitLineLine(Canvas c, LimitLine limitLine, float[] position) {
  mLimitLineSegmentsBuffer[0] = position[0];
  mLimitLineSegmentsBuffer[1] = mViewPortHandler.contentTop();
  mLimitLineSegmentsBuffer[2] = position[0];
  mLimitLineSegmentsBuffer[3] = mViewPortHandler.contentBottom();
  mLimitLinePath.reset();
  mLimitLinePath.moveTo(mLimitLineSegmentsBuffer[0], mLimitLineSegmentsBuffer[1]);
  mLimitLinePath.lineTo(mLimitLineSegmentsBuffer[2], mLimitLineSegmentsBuffer[3]);
  mLimitLinePaint.setStyle(Paint.Style.STROKE);
  mLimitLinePaint.setColor(limitLine.getLineColor());
  mLimitLinePaint.setStrokeWidth(limitLine.getLineWidth());
  mLimitLinePaint.setPathEffect(limitLine.getDashPathEffect());
  c.drawPath(mLimitLinePath, mLimitLinePaint);
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
protected void drawZeroLine(Canvas c) {
  int clipRestoreCount = c.save();
  mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
  mZeroLineClippingRect.inset(-mYAxis.getZeroLineWidth(), 0.f);
  c.clipRect(mLimitLineClippingRect);
  // draw zero line
  MPPointD pos = mTrans.getPixelForValues(0f, 0f);
  mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
  mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());
  Path zeroLinePath = mDrawZeroLinePathBuffer;
  zeroLinePath.reset();
  zeroLinePath.moveTo((float) pos.x - 1, mViewPortHandler.contentTop());
  zeroLinePath.lineTo((float) pos.x - 1, mViewPortHandler.contentBottom());
  // draw a path because lines don't support dashing on lower android versions
  c.drawPath(zeroLinePath, mZeroLinePaint);
  c.restoreToCount(clipRestoreCount);
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Draws the zero line.
 */
protected void drawZeroLine(Canvas c) {
  int clipRestoreCount = c.save();
  mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
  mZeroLineClippingRect.inset(0.f, -mYAxis.getZeroLineWidth());
  c.clipRect(mZeroLineClippingRect);
  // draw zero line
  MPPointD pos = mTrans.getPixelForValues(0f, 0f);
  mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
  mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());
  Path zeroLinePath = mDrawZeroLinePath;
  zeroLinePath.reset();
  zeroLinePath.moveTo(mViewPortHandler.contentLeft(), (float) pos.y);
  zeroLinePath.lineTo(mViewPortHandler.contentRight(), (float) pos.y);
  // draw a path because lines don't support dashing on lower android versions
  c.drawPath(zeroLinePath, mZeroLinePaint);
  c.restoreToCount(clipRestoreCount);
}

代码示例来源:origin: PhilJay/MPAndroidChart

protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans, XBounds bounds) {
  float fillMin = dataSet.getFillFormatter()
      .getFillLinePosition(dataSet, mChart);
  spline.lineTo(dataSet.getEntryForIndex(bounds.min + bounds.range).getX(), fillMin);
  spline.lineTo(dataSet.getEntryForIndex(bounds.min).getX(), fillMin);
  spline.close();
  trans.pathValueToPixel(spline);
  final Drawable drawable = dataSet.getFillDrawable();
  if (drawable != null) {
    drawFilledPath(c, spline, drawable);
  } else {
    drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
  }
}

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

@Test
public void testReset() throws Exception {
 Path path = new Path();
 path.moveTo(0, 3);
 path.lineTo(2, 3);
 path.quadTo(2, 3, 4, 5);
 path.reset();
 ShadowPath shadowPath = shadowOf(path);
 List<ShadowPath.Point> points = shadowPath.getPoints();
 assertEquals(0, points.size());
}

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

@Test
public void testLineTo() throws Exception {
 Path path = new Path();
 path.lineTo(2, 3);
 path.lineTo(3, 4);
 List<ShadowPath.Point> lineToPoints = shadowOf(path).getPoints();
 assertEquals(2, lineToPoints.size());
 assertEquals(new ShadowPath.Point(2, 3, LINE_TO), lineToPoints.get(0));
 assertEquals(new ShadowPath.Point(3, 4, LINE_TO), lineToPoints.get(1));
}

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

@Test
 public void test_copyConstructor() throws Exception {
  Path path = new Path();
  path.moveTo(0, 3);
  path.lineTo(2, 3);
  path.quadTo(2, 3, 4, 5);

  Path copiedPath = new Path(path);
  assertEquals(shadowOf(path).getPoints(), shadowOf(copiedPath).getPoints());
 }
}

相关文章