2017-04-02 39 views
-1

我需要绘制一个三角形,类似于使用Android中的Path附加下面的图像。你能对此提出宝贵的建议吗?如何在Android中使用Path绘制三角形?

我试着用下面的代码片段。如果在下面的代码片段中出错,请纠正我的错误。

 Android.Graphics.Point a = new Android.Graphics.Point(0, 0); 
     Android.Graphics.Point b = new Android.Graphics.Point(0, 100); 
     Android.Graphics.Point c = new Android.Graphics.Point(87, 100); 

     _path = new Path(); 
     _path.Reset(); 
     _path.LineTo(b.X, b.Y); 
     _path.LineTo(c.X, c.Y); 
     _path.LineTo(a.X, a.Y); 
     _path.Close(); 

预期输出:

enter image description here

回答

1

我觉得只是坐标是不正确的。

试试这个

Path _path = new Path(); 
    _path.reset(); 
    _path.moveTo(0,100); 
    _path.lineTo(87, 100); 
    _path.lineTo(87, 0); 
    _path.close(); 

    Paint paint = new Paint(); 
    paint.setColor(Color.RED); 
    canvas.drawPath(_path, paint); 
+0

对不起它没有制定出适合我。 – Parthiban

+0

@Parthiban你是在自定义视图上绘制这条路径吗? –

+0

是的,通过重写Xamarin Boxview – Parthiban