View a list using a bitmap

I am trying to create a small list view map where the entire list view is not displayed on the screen. I use

Bitmap mBitmap = fullView.getDrawingCache(); 

to create a bitmap image. It works fine for the list view part that is visible on the screen, but not for the part that is not. I would like to know whether it is possible to create a raster image of the list without displaying it completely on the screen. All suggestions and solutions are welcome.

+2
source share
2 answers

Since the android only draws what is visible, the idea may be to take bitmaps in pieces, and then group the bitmaps into one. First you can get a bitmap of the first n elements. Then use the scrollTo method to scroll through the previous n elements and get a bitmap for the next n elements. This way you can get a bitmap of the entire list.

0
source

Try using this method. The hack here calls the layout and method of measuring the view on its own.

 public Bitmap loadBitmapFromView(View v) { v.setLayoutParams(new ViewGroup.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); v.draw(c); return bitmap; } 

Pass the view in this method, for example

 LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View inflatedFrame = inflater.inflate(R.layout.my_view, null); Bitmap bitmap = loadBitmapFromView(inflatedFrame.findViewById(R.id.id_of_your_view_in_layout)); 
0
source

Source: https://habr.com/ru/post/908530/


All Articles