使用Canvas在Android上绘制两条线之间的区域 [英] Draw area between two lines using Canvas on Android

查看:1028
本文介绍了使用Canvas在Android上绘制两条线之间的区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序开发一个简单的统计图形类。我试过一个ChartEngine和其他人更多,但我更喜欢使用我自己的类。
我使用包括Android的Canvas类来绘制图形,但问题是我不知道如何填充线和底部边框之间的区域。
现在,矩形不填充所有的区域,显然,你知道任何解决方案吗?非常感谢。

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.

推荐答案

使用 路径 ,其中包含 Paint ,其中包含 .setStyle(Paint.Style.FILL);

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

这篇关于使用Canvas在Android上绘制两条线之间的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆