0

以下のコードは、テキストと画像を含むリストビュー配列を表示するために正しく機能しています

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

1 つの画像を連続して渡す場合は問題ありませんが、1 つの行に複数のビットマップを渡すと null 値が返されます。

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

2 行目に複数のビットマップがある場合の出力

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

0 に答える 0