qq_30130435
浅水咸鱼
采纳率72.7%
2016-08-16 01:12

继承surfaceview,用path.lineto为什么画不出线来?

4

我写的那个类想画由5个点链接起来的线,节点用小圆表示画出来了,可是线却画不出来。这是怎么回事,主要代码如下

public void draw() {
Canvas canvas = getHolder().lockCanvas();
canvas.drawColor(Color.WHITE);
int x=width/2,y=height/6,radius=10;
railPath.moveTo(x,y);
canvas.drawCircle(x, y, radius, circlePaint);
railPath.lineTo(x, y*2);
canvas.drawCircle(x, y*2, radius, circlePaint);
railPath.lineTo(x, y*3);
canvas.drawCircle(x, y*3, radius, circlePaint);
railPath.lineTo(x, y*4);
canvas.drawCircle(x, y*4, radius, circlePaint);
railPath.lineTo(x, y*5);
canvas.drawCircle(x, y*5, radius, circlePaint);
railPath.close();
canvas.drawPath(railPath, railPaint);
getHolder().unlockCanvasAndPost(canvas);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
draw();

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • huangf321123 keyborad_boy 5年前

    railPath初始化设置颜色了没。。。

    点赞 评论 复制链接分享
  • shayubuhuifei 鲨鱼不会飞 5年前

    你这个railPath初始化时在哪里?

    点赞 评论 复制链接分享