Call to `getDrawingCache` returns null when scroll is enabled

倾然丶 夕夏残阳落幕 提交于 2019-12-17 06:16:25

问题


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

回答1:


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..



来源:https://stackoverflow.com/questions/11560882/call-to-getdrawingcache-returns-null-when-scroll-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!