Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

android - 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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...