Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to `getDrawingCache` returns null when scroll is enabled

What is missing in this code? This same code works on ICS. On API 8 the scroll appears and some content goes out of screen. How to get the drawing cache in this case?

Code:

TableLayout page = (TableLayout) findViewById(R.id.page);
page.setDrawingCacheEnabled(true);
page.buildDrawingCache();

// getDrawingCache returns null...
Bitmap pageBmp = Bitmap.createBitmap(page.getDrawingCache(true));
page.destroyDrawingCache();
page.setDrawingCacheEnabled(false);
like image 367
Ronnie Avatar asked Jul 19 '12 12:07

Ronnie


1 Answers

I solved it. Created a bitmap of view size and drew the view into it.

TableLayout page = (TableLayout) findViewById(R.id.page);
Bitmap pageBmp = Bitmap.createBitmap(page.getWidth(), page.getHeight(), 
                                       Config.ARGB_8888);
Canvas canvas = new Canvas(pageBmp);
page.draw(canvas);

Used the pageBmp bitmap..

like image 101
Ronnie Avatar answered Sep 17 '22 22:09

Ronnie