Android Take Scrollview Screenshot Programmatically | Whole/Full/Long Activity Page

Android Take Scrollview Screenshot Tutorial with Example is your today’s guide.

When the screen size is limited but information on the single screen in large, we will simply use scrollview. But when you want to take the screenshot of the whole screen, some problems arise.

It is easy to take the screenshot of current screen but it is little tough when the screen have the scrollview with it.

With the simple and usual techniques, system will not capture the whole scrollview.

In this example, we will capture the whole scrollview programmatically even if it is double or more longer than the screen of the android device.

Normally, the pages having information about the person or school or organisation have more height than the average android device screen size. You must use scrollview in this scenarios.

In these cases, this tutorial will help you a lot and will save your time and efforts.

1. All Required Permissions

In this tutorial, you need to ask for required permissions.

Below are these permissions

If you are targeting sdk version greater than 22, then request for runtime permission with this tutorial.

I have set the target sdk version as 22, so no need for runtime permission here.

2. Setting up the scrollview

Update your activity_main.xml file with below source code

I have taken scrollview with six child views in it.

On the button click, system will capture the screenshot of the scrollview.

I have set three different images in above code. Download them by clicking below link.

Add following code into the file

Consider the below code

This is the code for the button click.

When the user will click the button, system will capture the screenshot of the scrollview.

A method named getBitmapFromView() will be executed here. We need to provide scrollview, it’s height and it’s length in the parameters of the getBitmapFromView() method.

Below is the code for getBitmapFromView() method.

It will create the bitmap from the view object of the scrollview, scrollview’s height and length.

getBitmapFromView() method will return the bitmap of the scrollview.

This bitmap can be used easily to store the image in the internal storage.

Saving the image

Following method will save the screenshot of the scrollview using the bitmap.

The bitmap returned by the getBitmapFromView() method will be passed as the parameter of the saveBitmap() method.

After saving the screenshot successfully, compiler will run the below coding lines.

This will simply open an activity which will preview the generated screenshot in an imageview.

For this, we need to create a new activity.

3. Previewing the screenshot

Make a new activity and give it a name “PreviewActivity”.

Add below code in activity_preview.xml

Write below code in file

There is one imageview in this activity. This image will show us the screenshot of the whole scrollview.

Screenshot is set into the imageview by below line

I have declared a bitmap called bitScroll as public static in the Main Activity.

So we can use it in any other activity of our app. Here, I have used that public bitScroll variable to set the image in preview activity.

All the words for android take scrollview screenshot tutorial with example are written completely.

If you have any doubt regarding this tutorial then, share it in comment section.

I will be happy to help you out and don’t forget to share our tutorials with others. Thanks!

Output Video

After completion of all above code stuff, you should get output like following video

Download Source Code for Android Take Scrollview Screenshot Example

Use below link to download the source code.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *