2

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

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

4

1 回答 1

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);
    }
于 2011-07-07T14:42:28.323 回答