0

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);

1 Answers1

0

what about this one? https://stackoverflow.com/a/16501007/2121682 your problems are same but methods are different. i hope it works. probably you've seen this one but just in case.

Community
  • 1
  • 1
iamkaan
  • 1,495
  • 2
  • 23
  • 43
  • I found all these answers on stackoverflow before, but non of them is working. I tried this one too but it does not make sense. Why does it draw canvas and then returns bitmap? It did not work, after i tried to take screenshot it just displaed blank page. – Martin Litvaj Mar 09 '14 at 18:18