RelativeLayout
is a subclass of View
, and the following should work for any view:
final View v; // The view that you want to save as an image
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
v.draw(c);
File outputFile; // Where to save it
FileOutputStream out = new FileOutputStream(imageFile);
boolean success = bitmap.compress(CompressFormat.PNG, 100, out);
out.close();
Add exception handling at your leisure. ;)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…