是否有任何现有的 Android 图形库可以让我绘制一条具有可调节数量的线段的线,并且可以实时触摸和拖动?我目前有一个使用 androidplot 的工作应用程序,它可以捕获我正在扫描的图像并绘制该数据的图表。我需要图表下方的可调整线段,以便用户可以选择将从数据收集的曲线和可调整线之间积分的区域。
我无法在 androidplot 中找到任何可以让我执行此操作的内容,如果需要的话,我可以切换图形库。
最佳答案
尝试查看路径
。这可能是最容易使用的类。
class Graph extends View {
Graph(Context context) {
super(context);
// ... Init paints
}
@Override public void onDraw(Canvas canvas) {
canvas.save(MATRIX_SAVE_FLAG);
// Draw Y-axis
canvas.drawLine(axisOffset, axisOffset, axisOffset, canvasHeight-axisOffset, paint);
// Draw X-axis
canvas.drawLine(axisOffset, canvasHeight-axisOffset, canvasWidth-axisOffset, canvasHeight-axisOffset, paint);
canvas.drawPath(new RectF(0.0f, 0.0f, 1.0f, 1.0f), mPath, paint);
canvas.restore();
}
Path mPath = new Path(); // your open path
float canvasWidth = 1.0f;
float canvasHeight= 1.0f;
float axisOffset = 0.1f; // The offset from the border of the canvas
public void registerDataPlot(int xCoord, int yCoord) {
// You need to convert the plot data to a location on the canvas
// Just find the percent value from the base of the axis
float x = xCoord / (canvasWidth - (2*axisOffset));
float y = yCoord / (canvasHeight - (2*axisOffset));
mPath.lineTo(x, y);
}
关于Android实时图形调整用户触摸屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6612279/