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


Java PathMeasure.setPath方法代碼示例

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


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

示例1: initPath

import android.graphics.PathMeasure; //導入方法依賴的package包/類
/**
 * 初始化 Path
 */
private void initPath() {
    mSearchPath = new Path();
    mCirclePath = new Path();
    mMeasure = new PathMeasure();

    RectF oval1 = new RectF(-50, -50, 50, 50);
    mSearchPath.addArc(oval1, 45, 359.9f); // 放大鏡的圓框

    RectF oval2 = new RectF(-100, -100, 100, 100);
    mCirclePath.addArc(oval2, 45, 359.9f); // 搜索的圓圈

    float[] pos = new float[2];
    mMeasure.setPath(mCirclePath, false);
    mMeasure.getPosTan(0, pos, null); // 放大鏡手柄的末端

    mSearchPath.lineTo(pos[0], pos[1]); // 放大鏡的手柄
}
 
開發者ID:Codpoe,項目名稱:Learn,代碼行數:21,代碼來源:SearchView.java

示例2: warpStraightLines

import android.graphics.PathMeasure; //導入方法依賴的package包/類
/**
 *  Make sure it can be seen in "FILL" mode
 */
private void warpStraightLines() {
    PathMeasure pmTemp = new PathMeasure();
    for (int i = 0; i < mConfig.complexity; i++) {
        if(lineRifts[i].isStraight())
        {
            pmTemp.setPath(lineRifts[i], false);
            lineRifts[i].setStartLength(pmTemp.getLength() / 2);
            float[] pos = new float[2];
            pmTemp.getPosTan(pmTemp.getLength() / 2, pos, null);
            int xRandom = (int) (pos[0] + Utils.nextInt(-Utils.dp2px(1), Utils.dp2px(1)));
            int yRandom = (int) (pos[1] + Utils.nextInt(-Utils.dp2px(1), Utils.dp2px(1)));
            lineRifts[i].reset();
            lineRifts[i].moveTo(0,0);
            lineRifts[i].lineTo(xRandom,yRandom);
            lineRifts[i].lineToEnd();
        }
    }
}
 
開發者ID:cowthan,項目名稱:AyoSunny,代碼行數:22,代碼來源:BrokenAnimator.java

示例3: draw

import android.graphics.PathMeasure; //導入方法依賴的package包/類
void draw(Canvas canvas, Paint paint, int color, float size, Path path) {
    PathMeasure mPathMeasure = new PathMeasure();
    float[] mPosition = new float[2];
    float[] mTan = new float[2];

    mPathMeasure.setPath(path, false);

    paint.setAntiAlias(true);
    paint.setColor(color);

    paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
    Bitmap brush;
    // done this way because of a bug in
    // Bitmap.createScaledBitmap(getBrush(),(int) size,(int) size,true);
    brush = createScaledBitmap(getBrush(), (int) size, (int) size, true);
    float len = mPathMeasure.getLength();
    float s2 = size / 2;
    float step = s2 / 8;
    for (float i = 0; i < len; i += step) {
        mPathMeasure.getPosTan(i, mPosition, mTan);
        //                canvas.drawCircle(pos[0], pos[1], size, paint);
        canvas.drawBitmap(brush, mPosition[0] - s2, mPosition[1] - s2, paint);
    }
}
 
開發者ID:asm-products,項目名稱:nexus-gallery,代碼行數:25,代碼來源:ImageFilterDraw.java

示例4: initPath

import android.graphics.PathMeasure; //導入方法依賴的package包/類
private void initPath() {
    innerCircle = new Path();
    outerCircle = new Path();
    trangle1 = new Path();
    trangle2 = new Path();
    drawPath = new Path();

    pathMeasure = new PathMeasure();

    RectF innerRect = new RectF(-220, -220, 220, 220);
    RectF outerRect = new RectF(-280, -280, 280, 280);
    innerCircle.addArc(innerRect, 150, -359.9F);     // 不能取360f,否則可能造成測量到的值不準確
    outerCircle.addArc(outerRect, 60, -359.9F);

    pathMeasure.setPath(innerCircle, false);

    float[] pos = new float[2];
    pathMeasure.getPosTan(0, pos, null);        // 獲取開始位置的坐標
    trangle1.moveTo(pos[0], pos[1]);
    pathMeasure.getPosTan((1f / 3f) * pathMeasure.getLength(), pos, null);
    System.out.println("pos : " + pos[0] + "  " + pos[1]);

    trangle1.lineTo(pos[0], pos[1]);
    pathMeasure.getPosTan((2f / 3f) * pathMeasure.getLength(), pos, null);
    trangle1.lineTo(pos[0], pos[1]);
    trangle1.close();

    pathMeasure.getPosTan((2f / 3f) * pathMeasure.getLength(), pos, null);
    Matrix matrix = new Matrix();
    matrix.postRotate(-180);
    trangle1.transform(matrix, trangle2);
}
 
開發者ID:yzbzz,項目名稱:beautifullife,代碼行數:33,代碼來源:GranzortView.java

示例5: initPath

import android.graphics.PathMeasure; //導入方法依賴的package包/類
/**
 * 初始化球體彈跳的路徑
 */
private void initPath() {
    path.reset();

    float intervalX = (viewWidth - 2 * defaultPadding) / (bounceCount + 1); //每次彈跳的間距
    PointF start = new PointF();//起點位置
    PointF control = new PointF(); //貝塞爾控製點
    PointF end = new PointF(); //貝塞爾結束點
    start.x = defaultPadding;
    start.y = viewHeight - defaultPaddingBottom;

    float controlOffsetY = viewHeight * 0.6f;  //控製點向上偏移量,0.6為調試值
    float deltaY = (1.2f * viewHeight + controlOffsetY) / (bounceCount + 1); //控製點高度遞減值,1.2為調試值

    PathMeasure tempPathMeasure = new PathMeasure();
    segmentLength = new float[bounceCount + 1];

    for (int i = 0; i <= bounceCount; i++) {
        control.x = start.x + intervalX * (i + 0.5f);
        control.y = -controlOffsetY + deltaY * i;
        end.x = start.x + intervalX * (i + 1);
        end.y = start.y;
        if (i == 0) {
            path.moveTo(start.x, start.y);
        }
        if (i == bounceCount) {
            end.y = viewHeight;
        }
        path.quadTo(control.x, control.y, end.x, end.y);

        tempPathMeasure.setPath(path, false);
        if (i == 0) { //第一次彈跳的上升階段不畫,記錄彈跳一半長度(為效果更好,實際取值0.45
            skipLength = tempPathMeasure.getLength() * 0.45f;
        }
        segmentLength[i] = tempPathMeasure.getLength();
    }

    pathMeasure.setPath(path, false);

    if (interCreater == null) {
        interCreater = new MultiDecelerateAccelerateInterpolator();
    }
    physicInterpolator = interCreater.createInterpolator(segmentLength);

    //        Log.d("ccy","total length = " + pathMeasure.getLength());
    //        for (int i = 0; i < segmentLength.length; i++) {
    //            Log.d("ccy","i = " + i +";length = " + segmentLength[i]);
    //        }
}
 
開發者ID:NicoLiutong,項目名稱:miaosou,代碼行數:52,代碼來源:BounceBallView.java

示例6: onDraw

import android.graphics.PathMeasure; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mPaint.setColor(getResources().getColor(R.color.colorAccent));
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(10);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setAntiAlias(true);

    canvas.save();
    canvas.translate(mWidth / 2, mHeight / 2);

    // Path 直線操作
    Path path = new Path();
    path.lineTo(200, 200);
    path.setLastPoint(200, 100);
    path.lineTo(200, 0);
    path.close();
    path.moveTo(400, 200);
    path.lineTo(400, 0);
    path.addRect(-300, -300, 300, 300, Path.Direction.CCW);
    path.setLastPoint(-400, 400);

    canvas.drawPath(path, mPaint);

    // Path 基本圖形操作
    mPaint.setColor(getResources().getColor(R.color.colorPrimary));
    Path path1 = new Path();
    Path path2 = new Path();
    path1.addRect(-100, -100, 100, 100, Path.Direction.CW);
    path2.addCircle(0, 0, 100, Path.Direction.CW);
    path1.addPath(path2, 0, -100);

    canvas.drawPath(path1, mPaint);

    // Path 弧線操作
    RectF rectF = new RectF(0, -400, 100, -300);
    Path path3 = new Path();
    path3.moveTo(0, -300);
    path3.lineTo(100, -200);
    path3.arcTo(rectF, 180, 180, true);

    canvas.drawPath(path3, mPaint);

    Path path4 = new Path();
    Path path5 = new Path();
    path4.addCircle(0, -600, 100, Path.Direction.CW);
    path5.addRect(-100, -700, 100, -500, Path.Direction.CW);
    path4.offset(100, 0, path5); // offset(float dx, float dy, Path dst) 中的 dx 和 dy 是偏移量,不是絕對量

    canvas.drawPath(path4, mPaint);
    mPaint.setColor(getResources().getColor(R.color.colorAccent));
    canvas.drawPath(path5, mPaint);

    Path path6 = new Path();
    path6.addCircle(0, 0, 300, Path.Direction.CW);
    PathMeasure pathMeasure = new PathMeasure();
    pathMeasure.setPath(path6, false);
    Path dst = new Path();
    pathMeasure.getSegment(pathMeasure.getLength() * 1.2f, pathMeasure.getLength() * 1.5f, dst, true);
    canvas.drawPath(dst, mPaint);

}
 
開發者ID:Codpoe,項目名稱:Learn,代碼行數:64,代碼來源:LearnView.java

示例7: measurePaths

import android.graphics.PathMeasure; //導入方法依賴的package包/類
/**
 * Perform measurements and pre-calculations. This should be called any time
 * the view measurements or visuals are changed, such as with a call to {@link #setPadding(int, int, int, int)}
 * or an operating system callback like {@link #onLayout(boolean, int, int, int, int)}.
 */
private void measurePaths() {
    int maxSize;
    float middle;

    maxSize = Math.min(getWidth(), getHeight());
    padding = Math.max(
          Math.max(getPaddingBottom(), getPaddingTop()),
          Math.max(getPaddingRight(), getPaddingLeft()));
    maxSize -= padding * 2;
    middle = maxSize / 2f;

    pathMeasure = new PathMeasure();

    PointF p1a = new PointF(middle, 0);
    PointF p1b = getCheckRightPoint(maxSize);

    firstPath = new Path();
    firstPath.moveTo(p1a.x, p1a.y);
    firstPath.lineTo(p1b.x, p1b.y);
    pathMeasure.setPath(firstPath, false);
    firstPathLength = pathMeasure.getLength();

    PointF p2a = new PointF(middle, maxSize);
    PointF p2b = getCheckMiddlePoint(maxSize);

    secondPath = new Path();
    secondPath.moveTo(p2a.x, p2a.y);
    secondPath.lineTo(p2b.x, p2b.y);
    pathMeasure.setPath(secondPath, false);
    secondPathLength = pathMeasure.getLength();

    PointF p3a = new PointF(0, middle);
    PointF p3b = getCheckLeftPoint(maxSize);

    thirdPath = new Path();
    thirdPath.moveTo(p3a.x, p3a.y);
    thirdPath.lineTo(p3b.x, p3b.y);
    pathMeasure.setPath(thirdPath, false);
    thirdPathLength = pathMeasure.getLength();

    PointF p4a = new PointF(maxSize, middle);

    fourPath = new Path();
    fourPath.moveTo(p4a.x, p4a.y);
    fourPath.lineTo(p2b.x, p2b.y);
    pathMeasure.setPath(fourPath, false);
    fourPathLength = pathMeasure.getLength();

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(color);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeCap(Paint.Cap.SQUARE);
    paint.setStrokeWidth(strokeWidth);

    fromXY = new float[]{0f, 0f};
    toXY = new float[]{0f, 0f};
}
 
開發者ID:aballano,項目名稱:CheckView,代碼行數:64,代碼來源:CheckView.java

示例8: buildBrokenLines

import android.graphics.PathMeasure; //導入方法依賴的package包/類
/**
 * Build warped-lines according to the baselines, like the DiscretePathEffect.
 */
private void buildBrokenLines(Rect r) {
    LinePath[] baseLines = new LinePath[mConfig.complexity];
    buildBaselines(baseLines, r);
    PathMeasure pmTemp = new PathMeasure();
    for (int i = 0; i < mConfig.complexity; i++) {
        lineRifts[i] = new LinePath();
        lineRifts[i].moveTo(0, 0);
        lineRifts[i].setEndPoint(baseLines[i].getEndPoint());

        pmTemp.setPath(baseLines[i], false);
        float length = pmTemp.getLength();
        final int THRESHOLD = SEGMENT + SEGMENT / 2;

        if (length > Utils.dp2px(THRESHOLD)) {
            lineRifts[i].setStraight(false);
            // First, line to the point at SEGMENT of baseline;
            // Second, line to the random-point at (SEGMENT+SEGMENT/2) of baseline;
            // So when we set the start-draw-length to SEGMENT and the paint style is "FILL",
            // we can make the line become visible faster(exactly, the triangle)
            float[] pos = new float[2];
            pmTemp.getPosTan(Utils.dp2px(SEGMENT), pos, null);
            lineRifts[i].lineTo(pos[0], pos[1]);

            lineRifts[i].points.add(new Point((int)pos[0], (int)pos[1]));

            int xRandom, yRandom;
            int step = Utils.dp2px(THRESHOLD);
            do{
                pmTemp.getPosTan(step, pos, null);
                // !!!
                // Here determine the stroke width of lineRifts
                xRandom = (int) (pos[0] + Utils.nextInt(-Utils.dp2px(3),Utils.dp2px(2)));
                yRandom = (int) (pos[1] + Utils.nextInt(-Utils.dp2px(2),Utils.dp2px(3)));
                lineRifts[i].lineTo(xRandom, yRandom);
                lineRifts[i].points.add(new Point(xRandom, yRandom));
                step += Utils.dp2px(SEGMENT);
            } while (step < length);
            lineRifts[i].lineToEnd();
        } else {
            // Too short, it's still a beeline, so we must warp it later {@warpStraightLines()},
            // to make sure it is visible in "FILL" mode.
            lineRifts[i] = baseLines[i];
            lineRifts[i].setStraight(true);
        }
        lineRifts[i].points.add(lineRifts[i].getEndPoint());
    }
}
 
開發者ID:cowthan,項目名稱:AyoSunny,代碼行數:51,代碼來源:BrokenAnimator.java

示例9: PathObj

import android.graphics.PathMeasure; //導入方法依賴的package包/類
/**
 * 初始化路徑
 *
 * @param bitmap 繪製的圖片
 */
public PathObj(Bitmap bitmap) {
    this.bitmap = bitmap;
    this.bitmapWidth = bitmap.getWidth();
    this.bitmapHeight = bitmap.getHeight();

    bitmapWidthDst = bitmapWidth;// + bitmapWidth/4;
    bitmapHeightDst = bitmapHeight;// + bitmapHeight/4;

    src = new Rect(0, 0, bitmapWidth, bitmapHeight);
    dst = new Rect(0, 0, bitmapWidthDst / 2, bitmapHeightDst / 2);

    paint = new Paint();
    paint.setAntiAlias(true);

    path = new Path();
    pathMeasure = new PathMeasure();

    int factor = 2;
    int initX = (int) mContext.getResources().getDimension(R.dimen.heart_anim_init_x);
    int initY = (int) mContext.getResources().getDimension(R.dimen.heart_anim_init_y);
    int xRand = (int) mContext.getResources().getDimension(R.dimen.heart_anim_bezier_x_rand);
    int animLengthRand = (int) mContext.getResources().getDimension(R.dimen.heart_anim_length_rand);
    int bezierFactor = 6;
    int animLength = (int) mContext.getResources().getDimension(R.dimen.heart_anim_length);
    int xPointFactor = (int) mContext.getResources().getDimension(R.dimen.heart_anim_x_point_factor);

    int x = mRandom.nextInt(xRand);
    int x2 = mRandom.nextInt(xRand);

    int y = getHeight() - initY;
    int y2 = animLength * factor + mRandom.nextInt(animLengthRand);

    factor = y2 / bezierFactor;

    x = xPointFactor + x;
    x2 = xPointFactor + x2;

    int y3 = y - y2;
    y2 = y - y2 / 2;

    path.moveTo(initX, y);
    path.cubicTo(initX, y - factor, x, y2 + factor, x, y2);
    path.moveTo(x, y2);
    path.cubicTo(x, y2 - factor, x2, y3 + factor, x2, y3);

    pathMeasure.setPath(path, false);
    length = (int) pathMeasure.getLength();
    speed = mRandom.nextInt(1) + 1f;
}
 
開發者ID:Geekince,項目名稱:HeartLikesView,代碼行數:55,代碼來源:HeartLikeView.java

示例10: getRestLength

import android.graphics.PathMeasure; //導入方法依賴的package包/類
private float getRestLength(Path path, float startD) {
    Path tempPath = new Path();
    PathMeasure pathMeasure = new PathMeasure(path, false);

    pathMeasure.getSegment(startD, pathMeasure.getLength(), tempPath, true);

    pathMeasure.setPath(tempPath, false);

    return pathMeasure.getLength();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:CircleBroodLoadingRenderer.java


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