softwaresupply softwaresupply - 5 months ago 18
Android Question

Take a screenshot of a whole View

I have built a table which is basically done by

HorizontalScrollView
inside a
ScrollView
. I made the user can edit the fields.

Now I want to save the table on a screen, jpg, png, pdf or anything else.

The problem is - the table is nearly always bigger than the screen.

Is there a way to make a screenshot of the whole
ScrollView
layout? If not what do you think can do the job?

Answer

Actually I found the answer:

public static Bitmap loadBitmapFromView(View v, int width, int height) {
    Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);                
    Canvas c = new Canvas(b);
    v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
    v.draw(c);
    return b;
}
Comments