onDraw fill shape create with canvas.drawLine

十年热恋 提交于 2019-12-04 17:11:53

You could fill the rect if you drew your line segments as a Path. But to just fill an area bounded by four unconnected but intersecting line segments, I think you'd have to write your own routine. Search for "flood fill" or "seed fill".

Dont use drawLine but, create Path object :

protected void onDraw(Canvas canvas) {


    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.parseColor("#FFA800"));


    Path path = new Path();

    path.moveTo(0, 0);
    path.lineTo(getWidth() / 2, 0);
    path.lineTo(getWidth(), getHeight()/2);
    path.lineTo(getWidth() / 2, getHeight());
    path.lineTo( 0, getHeight());
    path.lineTo( 0, 0);

    canvas.drawPath(path, paint);

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!