道客优

1234
如何把一个布局转化为Drawable
2019-03-02 刀刻油 阅读:1036

public staticDrawable layout2Drawable( int  layouId ){         

        LayoutInflater inflator = getLayoutInflater();
        View view = inflator.inflate(layouId, null);
        Bitmap bitmap = convertViewToBitmap(viewHelp);
        Drawable drawable = (Drawable)new BitmapDrawable(bitmap);
        return drawable;
     }

public static Bitmap convertView2Bitmap(View view) {
      view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
      MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
      view.layout(0, 0, width, view.getMeasuredHeight()); 
      view.buildDrawingCache();
      Bitmap bitmap = view.getDrawingCache();
      return bitmap;
}






推荐阅读: