0

So, basically i have next piece of code:

  llPhotoTest.setDrawingCacheEnabled(false);
  llPhotoTest.setDrawingCacheEnabled(true);
  ... 
  llPhotoTest.getDrawingCache();

First time everything is ok, but second time cached picture stay the same. I've seen a lot of solutions for this problem but nothing works for me. I would appreciate any help or suggestion. Thank you in advance

I've tried:

llPhotoTest.setDrawingCacheEnabled(true);
llPhotoTest.getDrawingCache();
llPhotoTest.setDrawingCacheEnabled(false);

Also I've tried

llPhotoTest.buildDrawingCache();
llPhotoTest.getDrawingCache();
llPhotoTest.destroyDrawingCache();

Still same picture :(

There is a layout bounds enter image description here

  • It would help people a lot if you would tell us what the solutions are that you saw and why they don't work for you. – LisaMM Jun 17 '15 at 10:55
  • cannot you just call `llPhotoTest.d[ispatchD]raw(canvas)` ? – pskink Jun 17 '15 at 10:56
  • There is no method `dispatchDraw(canvas)` –  Jun 17 '15 at 11:24
  • it is dispatchDraw(Canvas), but is protected, did you try draw()? – pskink Jun 17 '15 at 11:27
  • `Bitmap b = Bitmap.createBitmap(llPhotoTest.getWidth(), llPhotoTest.getHeight(), Bitmap.Config.ARGB_8888 ); Canvas canvas = new Canvas(b); llPhotoTest.draw(canvas);` b all time the same bitmap :( –  Jun 17 '15 at 11:35

2 Answers2

2

Thanks to everybody! I found solution, that's was an Issue. llPhotoTest.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

From documentation http://developer.android.com/reference/android/view/View.html#LAYER_TYPE_SOFTWARE:

Indicates that the view has a software layer. A software layer is backed by a bitmap and causes the view to be rendered using Android's software rendering pipeline, even if hardware acceleration is enabled.

0

That's not a good way to display a bitmap.

Use an ImageView, not a LinearLayout and call ImageView.setImageBitmap(Bitmap bm)

Andrew G
  • 2,596
  • 2
  • 19
  • 26
  • I've attached a picture with bounds. Looks like everything is ok in terms of bounds. –  Jun 17 '15 at 11:51
  • The thing is, I have hierarchy of elements and LinearLayout is inside root element. So in order to make a screenshot I am making a call to `llPhotoTest.getDrawingCache()`. There is no a problem in displaying image, the problem is same image all the time :( –  Jun 17 '15 at 12:09
  • I have no idea what that image is showing. You should try another method. `draw()` will need to be called every time the `View` is invalidated. Just use the classes that are already provided. I often use a `FrameLayout` and add many overlapping views to it. I would add the `LinearLayout` and the `ImageView` as children of this class and then instantiate the `Bitmap` or `Drawable` properly as yours is blank! – Andrew G Jun 17 '15 at 13:17
  • I found solution. This piece of code solved my Issue `llPhotoTest.setLayerType(View.LAYER_TYPE_SOFTWARE, null);` –  Jun 17 '15 at 13:25
  • You haven't solved my problem, but anyway thank you! –  Jun 17 '15 at 13:27
  • No probs. The reason why it was difficult to work this out is because you're working against Android conventions and design. `LinearLayout` is optimised to display a number of views along an axis, and not to be drawn on directly. I imagine changing the layerType to software may affect performance or cause undesired effects. Good luck hacking. – Andrew G Jun 17 '15 at 13:30