How do I draw an arrowhead (in Android)?

后端 未结 8 478
一个人的身影
一个人的身影 2020-11-29 06:29

I\'m fairly new to Android and have been toying around with Canvas. I\'m attempting to draw an arrow but I\'m only having luck with drawing the shaft, none of the arrowhead

相关标签:
8条回答
  • 2020-11-29 07:29

    How about using "Path myPath = new Path();" where you would give the x and y positions to create a triangle using lines and filling it. You can read about it, here is an example I took from somewhere.

    // create and draw triangles
    // use a Path object to store the 3 line segments
    // use .offset to draw in many locations
    // note: this triangle is not centered at 0,0
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(2);
    paint.setColor(Color.RED);
    Path path = new Path();
    path.moveTo(0, -10);
    path.lineTo(5, 0);
    path.lineTo(-5, 0);
    path.close();
    path.offset(10, 40);
    canvas.drawPath(path, paint);
    path.offset(50, 100);
    canvas.drawPath(path, paint);
    // offset is cumlative
    // next draw displaces 50,100 from previous
    path.offset(50, 100);
    canvas.drawPath(path, paint);
    
    0 讨论(0)
  • 2020-11-29 07:29

    Use a Path as below and adjust the co-ordinates accordingly:

    // Construct a wedge-shaped path
    Path mPath = new Path();
    mPath.moveTo(0, -50);
    mPath.lineTo(-20, 60);
    mPath.lineTo(0, 50);
    mPath.lineTo(20, 60);
    mPath.close();
    
    0 讨论(0)
提交回复
热议问题