如何在Android的总列表视图的屏幕截图 [英] How to take screenshot of total listview in android

查看:178
本文介绍了如何在Android的总列表视图的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图采取动态列表视图的屏幕截图,这是我的code

Trying to take screenshot of dynamic listview ,here is my code

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

在这里我得到空指针异常(listview.getAdapter())任何人都可以建议我如何解决这个问题。 继这也

here i am getting nullpointer exception(listview.getAdapter())could anyone suggest me how to fix this problem . Following this also

推荐答案

虽然不可能让还未呈现的内容的截图(如关闭屏幕项目的ListView的),你可以做一个多截图,每个镜头之间的滚动内容,然后拼接图像。下面是一个可以自动为你的工具: https://github.com/PGSSoft/scrollscreenshot

While it is impossible to make a screenshot of not-yet-rendered content (like off-screen items of the ListView), you can make a multiple screenshots, scroll content between each shot, then stitch images. Here is a tool which can automate this for you: https://github.com/PGSSoft/scrollscreenshot

免责声明:我是这个工具的作者,这是出版的我的雇主。功能要求是欢迎的。

Disclaimer: I'm author of this tool, it was published by my employer. Feature requests are welcome.

这篇关于如何在Android的总列表视图的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆