Android实时图形调整用户触摸屏

时间:2011-07-07 14:31:55

标签: android real-time graphing

是否有任何现有的Android图形库可以让我绘制一条可调整数量的段,可以实时触摸和拖动?我目前有一个使用androidplot的工作应用程序,它捕获我正在扫描的图像并绘制该数据的图像。我需要在图表下方调整线段,以便用户可以选择将在从数据和可调整线收集的曲线之间进行整合的区域。

我无法在androidplot中找到任何可能允许我这样做的内容,如果需要,我可以切换图形库。

1 个答案:

答案 0 :(得分:3)

尝试查看Path。这可能是最容易使用的课程。

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);
    }