【问题标题】:draw line between two cordinates in ondraw() in android在android的ondraw()中的两个坐标之间画线
【发布时间】:2013-03-21 09:46:42
【问题描述】:

我有两点,比如说 (x1,y1) 和 (x2,y2)。现在我必须使用OnDraw() 方法在这些点之间画一条线。

我试过了

Paint mPaint = new Paint()     
mPaint.setColor(Color.BLACK);    
path.moveTo(x1, y1);    
path.lineTo(x2, y2);

canvas.drawPath(path, mPaint);

但它不起作用

问候,

苏迪尔

【问题讨论】:

  • 怎么不工作了?会发生什么?
  • 请添加一些关于什么不起作用的详细信息,并检查 x1,x2,y1,y2 是否具有合理的值(例如,不在可见区域之外)。该代码对我来说看起来不错,应该可以工作。

标签: android canvas line


【解决方案1】:

这样试试

canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-04
    • 2012-06-10
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多