当前位置:   article > 正文

Android 把Layout变成图片_android layoutinflater.from(context)的布局变成图片

android layoutinflater.from(context)的布局变成图片

首先是XML读取

  1. LinearLayout layout = (LinearLayout) LayoutInflater.from(
  2. mContext).inflate(R.layout.hotel_map_pop, null);

然后:

  1. layout.setDrawingCacheEnabled(true);
  2. layout.measure(MeasureSpec.makeMeasureSpec(0,
  3. MeasureSpec.UNSPECIFIED), MeasureSpec
  4. .makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
  5. layout.layout(0, 0, layout.getMeasuredWidth(),
  6. layout.getMeasuredHeight());
  7. layout.buildDrawingCache();
  8. Bitmap bitmap = layout.getDrawingCache();

然后,一个Layout就可以变成一个Bitmap啦

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/262128
推荐阅读
相关标签
  

闽ICP备14008679号