You do not want:
Bitmap viewBmp = Bitmap.createBitmap(view.getLayoutParams().width, view.getLayoutParams().height,
Bitmap.Config.ARGB_8888);
The LayoutParams
does not normally have the actual width and height. Often it has negative values, indicating wrap_content
or match_parent
.
Instead, try:
Bitmap viewBmp = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
Bitmap.Config.ARGB_8888);
or something along those lines. You want the actual width and height of the container, not the width and height requested by its LayoutParams
.