所有的ListView项目的Andr​​oid获取屏幕截图 [英] Android get screenshot of all ListView items

查看:112
本文介绍了所有的ListView项目的Andr​​oid获取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 视图V = rootView.findViewById(R.id.layout1);
如果(V!= NULL){
    v.buildDrawingCache();
    点阵位图= v.getDrawingCache();
    canvas.drawBitmap(位图,dummyMatrix,NULL);
    v.destroyDrawingCache();
}
 

我有这个code。但我需要截图我所有的ListView的项目,但如果我的列表视图的屏幕上有较明显的更多的项目,这code不捕获时比可见矩形更大的项目。

如何正确捕获我的ListView?

新的工作code由我创建

 公共静态位图getWholeListViewItemsToBitmap(){

    ListView控件列表视图= MyActivity.mFocusedListView;
    ListAdapter适配器= listview.getAdapter();
    INT itemscount = adapter.getCount();
    INT allitemsheight = 0;
    名单<位图>骨形态发生蛋白=新的ArrayList<位图>();

    的for(int i = 0; I< itemscount;我++){

        查看childView = adapter.getView(I,空,列表视图);
        childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(),MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED));

        childView.layout(0,0,childView.getMeasuredWidth(),childView.getMeasuredHeight());
        childView.setDrawingCacheEnabled(真正的);
        childView.buildDrawingCache();
        bmps.add(childView.getDrawingCache());
        allitemsheight + = childView.getMeasuredHeight();
    }

    位图bigbitmap = Bitmap.createBitmap(listview.getMeasuredWidth(),allitemsheight,Bitmap.Config.ARGB_8888);
    帆布bigcanvas =新的Canvas(bigbitmap);

    涂料粉刷=新的油漆();
    INT IHEIGHT = 0;

    的for(int i = 0; I< bmps.size();我++){
        BMP位= bmps.get(我);
        bigcanvas.drawBitmap(BMP,0,IHEIGHT,油漆);
        IHEIGHT + = bmp.getHeight();

        bmp.recycle();
        BMP = NULL;
    }


    返回bigbitmap;
}
 

解决方案

工作code:

 公共静态位图getWholeListViewItemsToBitmap(){

    ListView控件列表视图= MyActivity.mFocusedListView;
    ListAdapter适配器= listview.getAdapter();
    INT itemscount = adapter.getCount();
    INT allitemsheight = 0;
    名单<位图>骨形态发生蛋白=新的ArrayList<位图>();

    的for(int i = 0; I< itemscount;我++){

        查看childView = adapter.getView(I,空,列表视图);
        childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(),MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED));

        childView.layout(0,0,childView.getMeasuredWidth(),childView.getMeasuredHeight());
        childView.setDrawingCacheEnabled(真正的);
        childView.buildDrawingCache();
        bmps.add(childView.getDrawingCache());
        allitemsheight + = childView.getMeasuredHeight();
    }

    位图bigbitmap = Bitmap.createBitmap(listview.getMeasuredWidth(),allitemsheight,Bitmap.Config.ARGB_8888);
    帆布bigcanvas =新的Canvas(bigbitmap);

    涂料粉刷=新的油漆();
    INT IHEIGHT = 0;

    的for(int i = 0; I< bmps.size();我++){
        BMP位= bmps.get(我);
        bigcanvas.drawBitmap(BMP,0,IHEIGHT,油漆);
        IHEIGHT + = bmp.getHeight();

        bmp.recycle();
        BMP = NULL;
    }


    返回bigbitmap;
}
 

View v = rootView.findViewById(R.id.layout1);
if (v != null) {
    v.buildDrawingCache();
    Bitmap bitmap = v.getDrawingCache();
    canvas.drawBitmap(bitmap, dummyMatrix, null);
    v.destroyDrawingCache();   
}

I have this code. But I need to screenshot all my ListView items, but if my listview's have more items than visible on the screen, this code don't capture when the items bigger than the visible rect.

How to capture my ListView correctly?

NEW WORKING CODE CREATED BY ME

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

解决方案

working 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项目的Andr​​oid获取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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