在listview数组位图中获取null值

时间:2013-10-11 10:54:28

标签: android android-layout android-listview bitmap

以下代码正常工作以显示带有文本和图像的列表视图数组

public static Bitmap getWholeListViewItemsToBitmap() {


    ListAdapter adapter  = list.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()); //here only getting null value 
        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;
}

如果我连续传递一个图像没有问题,但如果我在一行中传递多个位图,则获取空值。

arr_media = db.showmedia(logid, arr_name.get(position), "photo");
            for(int i=0;i<arr_media.size();i++)
            { 
                ImageView iv = new ImageView(PDFActivity.this);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(200, 200);
                iv.setLayoutParams(new LayoutParams(200, 200));
                BitmapFactory.Options o = new BitmapFactory.Options();
                o.inJustDecodeBounds = true; 
                try {
                    BitmapFactory.decodeStream(new FileInputStream(arr_media.get(i)),null,o);
                    final int REQUIRED_SIZE=200;
                    int scale=1;
                    while(o.outWidth/scale/2>=REQUIRED_SIZE && o.outHeight/scale/2>=200)
                        scale*=2;
                    BitmapFactory.Options o2 = new BitmapFactory.Options();
                    o2.inSampleSize=2;
                    bm = BitmapFactory.decodeStream(new FileInputStream(arr_media.get(i)), null, o2);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                params.setMargins(0, 10, 0, 0); 
                iv.setImageBitmap(bm);
                layout.addView(iv,params);
            }
            arr_text = db.showtext(logid, arr_name.get(position), "text");
            for(int j=0;j<arr_text.size();j++)
            {
                String value = readFile(arr_text.get(j));
                TextView tv = new TextView(PDFActivity.this);
                TextView tv1 = new TextView(PDFActivity.this);
                tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                tv1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                int j1 = j + 1;
                tv1.setText("Text"+j1);
                tv1.setTypeface(null, Typeface.BOLD);
                tv.setText(value.replace("null", ""));
                layout.addView(tv1);
                layout.addView(tv);
            }

在第二行中有多个位图时输出

[android.graphics.Bitmap@41a414c0, null, android.graphics.Bitmap@41a3e5d0]

0 个答案:

没有答案