-1

Say I have a LinearLayout that contains multiple WebViews and I need to take a screenshot of it.

The only idea that comes to mind is taking a screen of each individual webview onPageFinished and then combining them. Yet it is a hell lot of work and the result won't be too accurate.

Maybe someone know of some top-secret :) method that can be used in this case?

Thanks!

Roger Travis
  • 8,402
  • 18
  • 67
  • 94

1 Answers1

1

You could draw the LinearLayout to a Bitmap. Since it is the parent of the WebView´s you can use its draw method to get a screenShot.

eks.

    LinearLayout root = findViewById(R.id.root);
    Bitmap bitmap = Bitmap.createBitmap(root.getWidth(), root.getHeight(), Config.ARGB_8888);
    final Canvas canvas= new Canvas(bitmap);
    root.draw(canvas);

TODO: Do something with the bitmap. 

Note, that you need to wait until the WebView´s are finished loading in order for this to work correctly...

Zelleriation
  • 2,834
  • 1
  • 23
  • 23