Android获取所有ListView项目的屏幕截图

Android获取所有ListView项目的屏幕截图,第1张

Android获取所有ListView项目的屏幕截图

工作代码:

public static Bitmap getWholeListViewItemsToBitmap() {    ListView listview    = MyActivity.mFocusedListView;    ListAdapter adapter  = listview.getAdapter();     int itemscount       = adapter.getCount();    int allitemsheight   = 0;    List<Bitmap> bmps    = new ArrayList<Bitmap>();    for (int i = 0; i < itemscount; i++) {        View childView      = adapter.getView(i, null, listview);        childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.EXACTLY),      MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));        childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());        childView.setDrawingCacheEnabled(true);        childView.buildDrawingCache();        bmps.add(childView.getDrawingCache());        allitemsheight+=childView.getMeasuredHeight();    }    Bitmap bigbitmap    = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight, Bitmap.Config.ARGB_8888);    Canvas bigcanvas    = new Canvas(bigbitmap);    Paint paint = new Paint();    int iHeight = 0;    for (int i = 0; i < bmps.size(); i++) {        Bitmap bmp = bmps.get(i);        bigcanvas.drawBitmap(bmp, 0, iHeight, paint);        iHeight+=bmp.getHeight();        bmp.recycle();        bmp=null;    }    return bigbitmap;}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4889935.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存