Hussnain Azam
Hussnain Azam

Reputation: 358

Draw custom shape on canvas in android using path

I am trying to draw a shape (shape1) on canvas using path class but not able to draw it.However i am able to make a shape (shape2) using pathclass Shape

code for shape2(Dotted) is given below

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

    int h = getMeasuredHeight();
    int w = getMeasuredWidth();

    int value = (w/2)-90;
    Path path = new Path();
    path.lineTo(value, 0);
    path.lineTo(value + 120, h);
    path.moveTo(value + 120, h);
    path.lineTo(-W, h);
    path.close();
    canvas.drawPath(path, bgPaint);

}

I am unable to manoeuvre above code to achieve shape1

Upvotes: 0

Views: 4878

Answers (1)

andrei
andrei

Reputation: 2940

it should be something like

path.moveTo(0, 0);
path.lineTo(value, 0);
path.lineTo(value + delta, h);
path.lineTo(delta, h);
path.lineTo(0, 0);

where delta is 120 in your case

Upvotes: 2

Related Questions