在Android上使用Canvas两条线之间绘制区域 [英] Draw area between two lines using Canvas on Android
问题描述
我发展我的应用程序一个简单的统计图形类。我试过aChartEngine和别人多,但我preFER用我自己的类。
我画的图形Canvas类,包括Android的,但问题是,我不知道怎么填线与下边框之间的区域。
眼下,该矩形不填充所有区域,很明显,你知道有什么解决办法?非常感谢。
I'm developing a simple statistical graphics class for my application. I've tried aChartEngine and others more, but I prefer use my own classes. I'm drawing the graphics with the Canvas class that includes Android, but the problem is that I don't know how to fill the area between the line and the bottom border. Right now, the rectangles don't fill all the area, obviously, do You know any solution? Thanks a lot.
推荐答案
使用一个 路径
,具有 涂料
有<一个href=\"http://developer.android.com/reference/android/graphics/Paint.html#setStyle%28android.graphics.Paint.Style%29\"><$c$c>.setStyle(Paint.Style.FILL);$c$c>调用。
Use a Path
, with a Paint
which has .setStyle(Paint.Style.FILL);
called.
Path fillPath = new Path();
fillPath.moveTo(0, 0); // Your origin point
fillPath.lineTo(x1, y1); // First point
// Repeat above line for all points on your line graph
fillPath.lineTo(xN, yN); // Final point
fillPath.lineTo(xN, 0); // Draw from final point to the axis ++
fillPath.lineTo(0, 0); // Same origin point
yourCanvas.drawPath(fillPath, /* Your paint */);
的 ++感谢 @TheCapn 这一点。的
++ Thanks to @TheCapn for this bit.
这篇关于在Android上使用Canvas两条线之间绘制区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!