There are few thread about save layout as image here and here. What if I have a list view, and it is impossible to make them display on one screen.
Asked
Active
Viewed 1,045 times
2
-
Are the height of each item fixed or they can change? – 4gus71n Apr 28 '15 at 18:58
-
This helps maybe: http://stackoverflow.com/questions/12742343/android-get-screenshot-of-all-listview-items – Samurai Apr 28 '15 at 19:03
2 Answers
1
Try with this:
First enable the drawing cache in your ListView
vListView.setDrawingCacheEnabled(true);
Then adjust the size of the ListView
to make every item visible.
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) vListView.getLayoutParams();
params.height = (int) (mAdapter.getItemCount() * getResources().getDimension(R.dimen.max_item_height));
vListView.setLayoutParams(params);
Finally you can use either a callback or do a postDelayed with a Handler and get the bitmap.
vListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
drawingCache = vListView.getDrawingCache();
}
});
Let me know if it did help you.
BTW Remember that in Android Studio, in debug mode, you can check the bitmap variables contents.

4gus71n
- 3,717
- 3
- 39
- 66
0
You have to add it in hierarchy or it won't compute its layout. But no one says you have to actually show it on screen - create layout in which you can place ListView outside of screen bounds and use drawing cache to construct widget image.

weaknespase
- 1,014
- 8
- 15