The main issue is saving the whole scroll view as a bitmap image rather than just what appears on the screen. Is there a way to save whole scroll view, and if so how?
Asked
Active
Viewed 7,691 times
5
-
@Govind Rathod this is not working it gives screenshot only the screen not whole scrollview – user3693635 Jun 02 '14 at 07:27
3 Answers
2
Make a RelativeLayout or LinearLayout in your ScrollView to get Bitmap from Layout.
Organize this way:
public class ActivityA extends Activity {
LinearLayout PP_Ll;
Button btn_capture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PP_Ll = (RelativeLayout) findViewById(R.id.PP_Ll);
Button btn_capture= (Button) findViewById(R.id.btn_capture);
btn_capture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
}
});
public Bitmap takeScreenshot() {
View rootView = getWindow().getDecorView().findViewById(R.id.PP_Ll);
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File newDir = new File(root + "/Folder");
newDir.mkdirs();
Random gen = new Random();
int n = 10000;
n = gen.nextInt(n);
String fotoname = "Photo-" + n + ".jpg";
File file = new File(newDir, fotoname);
if (file.exists())
file.delete();
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
Toast.makeText(getApplicationContext(),
"Saved in folder: 'Folder'", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
}}
Your RelativeLayout will be saved in certain directory as a BitMap. Good luck.
Note: You have to insert your imageviews, textviews etc. into your RelativeLayout in .xml file that all can go into screenshot.

Umit Kaya
- 5,771
- 3
- 38
- 52
-
it gives only the scree which is show not the whole scrollview which is scrolled below – user3693635 Jun 02 '14 at 07:30
-
have u put ur textviews, imageview whatever inside layout. like this:
– Umit Kaya Jun 02 '14 at 07:33 -
-
-
well, if u can post your java code and .xml in ur question above i ll try to demonstrate u. update ur question. – Umit Kaya Jun 02 '14 at 08:00
-
here xml code [link](http://pastebin.com/eA3fCthj) and here java code [link](http://pastebin.com/tHCMRpH5) – user3693635 Jun 02 '14 at 09:09
-
i updated the answer. and for attention: make sure u declare LinearLayout and give the names accordingly. try this and let me know. – Umit Kaya Jun 02 '14 at 09:55
-
and pls lemme know whether u get the Toast: "Saved in folder: 'Folder'" after ur button click – Umit Kaya Jun 02 '14 at 09:56
-
it is not gives the whole scrollview image. it just gives the image which is show on screen please help me out of this problem due to this my project is not complete so please please help me – user3693635 Jun 04 '14 at 04:38
0
try below code:-
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;
}
see below link
-
i have tried that but it is not working properly it only gives the image of screen which is shown not the whole scroll view which is below of screen so please help me out for this problem it is urgent please help me thanks in advance @Golu – user3693635 Jun 02 '14 at 04:22
-
-1
Possible solution, you can create a emulator of larger screen size maybe 10inch, and run your app on it, If your listview fits into the screen, you can take a screen shot of it.

zIronManBox
- 4,967
- 6
- 19
- 35
-
i have tried that but it is not working properly it only gives the image of screen which is shown not the whole scroll view which is below of screen so please help me out for this problem it is urgent please help me thanks in advance @Golu – user3693635 Jun 02 '14 at 04:18
-
-
only one Linear Layout and but this linear layout have many textviews – user3693635 Jun 02 '14 at 07:26
-