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?
Download source code from here (Take screenshot of scrollview in android programmatically)
activity_main.xml
MainActivity.xml
Thanks!
It is impossible to make a screenshot of not-yet-rendered content (like off-screen parts of the ScrollView). However, you can make a multiple screenshots, scrolling content between each shot, then join images. Here is a tool which can automate this for you: https://github.com/PGSSoft/scrollscreenshot
Disclaimer: I'm author of this tool, it was published by my employer. Feature requests are welcome.
You can pass the view a fresh instance of a Canvas built upon a Bitmap object.
Try with
It actually did the job for me.
Taking a screenshot of a view, pass the view in the parameter
I've tested a lot of codes and every time hitting
NullPointerExeption
. I discovered that when our view does not have a parent view, the provided width and height (Xml or Java) get ignored and get setted toMATCH_PARENT
.Finally I came up with this solution:
You might be able to use the drawing cache of a view, but I am not sure if this will hold the entire view or just what is rendered to the screen.
I would advise you hunt around on StackOverflow for similar questions, it has more than likely been asked before.