Android中View转换为Bitmap及getDrawingCache=null的解决方法

public static Bitmap convertViewToBitmap(View view){
      view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
        view.buildDrawingCache();
        Bitmap bitmap = view.getDrawingCache();

     return bitmap;


注意:view 使用 "getMeasuredWidth()" and "getMeasuredHeight()"方法计算长宽。此时,Bitmap就能正确获取了。
原文地址:https://www.cnblogs.com/BoYu045535/p/5015004.html