I have an app which displays a table/matrix of a Math exercise. This table can be really big so I use vertical and horizontal layout. I need to take a screenshot of the whole layout, but it only saves screenshot of visible screen. What should I do?
This is my layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myScrollView"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<HorizontalScrollView
android:id="@+id/myHorizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TableLayout
android:id="@+id/myTableLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="1" />
</HorizontalScrollView>
</ScrollView>
This is how I take screenshot but only visible screen, not whole layout
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap myBitmap = v1.getDrawingCache();
saveBitmap(myBitmap); // saves to storage
Edit: With this code, I can take screenshot of very wide table but if it is also too high, app crashes and it says: View too large to fit into drawing cache, needs 2030336 bytes, only 1536000 available . Now I dont know if the problem is method I am using to capture the view or it is simply not possible to capture table with for example 20 rows and columns. Why is the bitmap so big?
TableLayout tableView = (TableLayout) findViewById(R.id.myTableLayout);
tableView.setDrawingCacheEnabled(true);
tableView.layout(0, 0, tableView.getWidth(), tableView.getHeight());
tableView.buildDrawingCache(true);
tableView.setBackgroundColor(Color.WHITE);
Bitmap bitmap = Bitmap.createBitmap(tableView.getDrawingCache());
tableView.setDrawingCacheEnabled(false);