Androidplot无法捕获屏幕截图

Androidplot无法捕获屏幕截图,androidplot,Androidplot,当我尝试使用Androidplot拍摄我的活动截图时,我收到一条“无法捕获截图-存储可能正在使用”的消息。如果没有在活动上放置Androidplot图,我可以完美地截图 private void renderAndroidPlot() { // on ICS+ devices :-) getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManage

当我尝试使用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));



}

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

getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
    WindowManager.LayoutParams.FLAG_SECURE);
将其从代码中删除,屏幕截图应该可以工作

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

这个有趣的小方块是为了让用户无法截图。删除它,您就可以截图了。

您可以显示一些简单的代码片段吗?我刚刚用代码更新了我的主要查询-谢谢。您知道这个问题是在2014年提出的吗?另外,你的答案与另一个已经发布的答案相同。请只在迟交的答案与之前的答案有显著差异或有所改进的情况下才发布。