setDrawingCacheEnabled 不适用于 LinearLayout

setDrawingCacheEnabled doesn't work on LinearLayout

所以,基本上我有下一段代码:

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

第一次一切正常,但第二次缓存的图片保持不变。 我已经看到很多解决这个问题的方法,但对我来说没有用。我将不胜感激任何帮助或建议。提前谢谢你

我试过:

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

我也试过了

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

还是一样的图片:(

有布局边界

这不是显示位图的好方法。

使用 ImageView,而不是 LinearLayout 并调用 ImageView.setImageBitmap(Bitmap bm)

谢谢大家!我找到了解决方案,这是一个问题。 llPhotoTest.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

来自文档 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.