Created
September 8, 2018 20:07
-
-
Save Binary-Finery/6303fb7cd4083bbb6ec02b0d93eefca9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Bitmap getWholeListViewItemsToBitmap() { | |
ListAdapter adapter = listView.getAdapter(); | |
int itemsCount = adapter.getCount(); | |
int allItemsHeight = 0; | |
List<Bitmap> bitmaps = new ArrayList<Bitmap>(); | |
for (int i = 0; i < itemsCount; i++) { | |
View childView = adapter.getView(i, null, listView); | |
childView.measure(View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); | |
childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight()); | |
childView.setDrawingCacheEnabled(true); | |
childView.buildDrawingCache(); | |
bitmaps.add(childView.getDrawingCache()); | |
allItemsHeight += childView.getMeasuredHeight(); | |
} | |
Bitmap bitmap = Bitmap.createBitmap(listView.getMeasuredWidth(), allItemsHeight, Bitmap.Config.ARGB_8888); | |
Canvas canvas = new Canvas(bitmap); | |
Paint paint = new Paint(); | |
int iHeight = 0; | |
for (int i = 0; i < bitmaps.size(); i++) { | |
Bitmap bmp = bitmaps.get(i); | |
canvas.drawBitmap(bmp, 0, iHeight, paint); | |
iHeight += bmp.getHeight(); | |
bmp.recycle(); | |
} | |
return bitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment