完成android后填充路径

时间:2015-08-04 07:25:40

标签: java android

我希望我的应用在完成后自动填充形状。我已经自动完成了形状,完成后我想让它们自动填充。代码发布在下面。我在onDraw中使用了mPath.setFillType,但这不起作用。

   @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if(mBitmap!=null){
    canvas.drawBitmap(drawableBitmap, 0, 0, mBitmapPaint);
    mPath.setFillType(Path.FillType.EVEN_ODD);

    canvas.drawPath( mPath,  mPaint);

    canvas.drawPath( circlePath,  circlePaint);}
    else{}
    }

    private float mX, mY;
    private static final float TOUCH_TOLERANCE = 4;

    private void touch_start(float x, float y) {
        Point point1=new Point();

        point1.x= (int) (x);
        point1.y = (int) (y);

        if(point1!=null)
        {
            points.add(point1);

        }
        else
        {
            System.out.println("POINT IS NULLlllllllllllllllllllllllllll");
        }
        mPath.reset();
    mPath.moveTo(x, y);
    mX = x;
    mY = y;
    }
    private void touch_move(float x, float y) {
        float dx = Math.abs(x - mX);
    float dy = Math.abs(y - mY);
    if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
         mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
        mX = x;
        mY = y;

        circlePath.reset();
        circlePath.addCircle(mX, mY, 30, Path.Direction.CW);
    }
    }
    private void touch_up(float x,float y) {

        Point point=new Point();

        point.x= (int) (x);
        point.y = (int) (y);

        points.add(point);

        mPath.lineTo(mX, mY);
        mPath.lineTo(points.get(0).x, points.get(0).y);

        circlePath.reset();
    // commit the path to our offscreen
    if(mCanvas!=null)
    mCanvas.drawPath(mPath,  mPaint);




   points.clear();

    mPath.reset();
    }

    @Override
    public boolean onTouch(View arg0, MotionEvent arg1) {
    float x = arg1.getX();
    float y = arg1.getY();

    switch (arg1.getAction()) {
        case MotionEvent.ACTION_DOWN:
            touch_start(x, y);
            invalidate();
            break;
        case MotionEvent.ACTION_MOVE:
             System.out.println("TOUCH MOVEEEEE");       
            touch_move(x, y);
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            touch_up(x,y);
            invalidate();
            break;
    }
    return true;
    }

0 个答案:

没有答案