Androidplot无法捕获截图

时间:2014-09-16 05:05:50

标签: androidplot

当我尝试截取我使用Androidplot的活动的屏幕截图时,我会得到一个“无法捕获捕获截图” - 存储空间可能正在使用中'信息。如果Androidplot图没有放在活动上,我可以完美地截取屏幕截图。

private void renderAndroidPlot()
{
    // on ICS+ devices :-)
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
            WindowManager.LayoutParams.FLAG_SECURE);

    // initialize our XYPlot reference:
    plot = (XYPlot) getView().findViewById(R.id.mySimpleXYPlot);

    // Create a couple arrays of y-values to plot:
    Number[] series1Numbers =   getGraphData();

    // Turn the above arrays into XYSeries':
    XYSeries series1 = new SimpleXYSeries(
            Arrays.asList(series1Numbers),          // SimpleXYSeries takes a List so turn our array into a List
            SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, // Y_VALS_ONLY means use the element index as the x value
            "Series1");                             // Set the display title of the series


    // add a new series' to the xyplot:
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.setBorderStyle(Plot.BorderStyle.NONE, null, null);

    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.parseColor("#99E6B1"), Shader.TileMode.MIRROR));
    LineAndPointFormatter formatter  = new LineAndPointFormatter(Color.rgb(0, 0,0), null, null,null);
    formatter.setFillPaint(lineFill);

    plot.setPlotMargins(0, 0, 0, 0);
    plot.setPlotPadding(0, 0, 0, 0);

    plot.getGraphWidget().setMarginTop(30);
    plot.getGraphWidget().setMarginRight(50);
    plot.getGraphWidget().setMarginLeft(50);
    plot.getGraphWidget().setMarginBottom(50);



    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);


    // reduce the number of range labels
    plot.setTicksPerRangeLabel(3);
    plot.getGraphWidget().setDomainLabelOrientation(0);

    //Remove legend
    plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    plot.setDomainStep(XYStepMode.SUBDIVIDE, 6);

    plot.addSeries(series1, formatter); //new LineAndPointFormatter(Color.parseColor("#2E64FE"), null, null, null));



}

2 个答案:

答案 0 :(得分:1)

这是由于包含这一行的示例代码中的一个不幸的错误:

getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
    WindowManager.LayoutParams.FLAG_SECURE);

从代码中删除它,屏幕截图应该有效。

答案 1 :(得分:0)

// on ICS+ devices :-)
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
        WindowManager.LayoutParams.FLAG_SECURE);

制作了这个有趣的小块,因此用户无法截取屏幕截图。删除它,您将能够截取屏幕截图。