我有一个名为的相对布局rel
,它动态地向它添加一个 imageview,如下所示:
rel.setBackgroundResource(R.drawable.bg_share_one);
RelativeLayout.LayoutParams p1 = new RelativeLayout.LayoutParams(921, 691);
p1.leftMargin = 30;
p1.topMargin = 30;
ImageView img = new ImageView(this);
img.setLayoutParams(p1);
myBitmap = BitmapFactory.decodeFile(files[0].getAbsolutePath(), option1);
img.setImageBitmap(myBitmap);
rel.addView(img);
saveCompareImage();
然后我调用此方法来截取该相对布局的屏幕截图,但它添加的图像视图未显示在位图中:
protected void saveCompareImage() {
// TODO Auto-generated method stub
rel.setDrawingCacheEnabled(true);
try {
File file = new File("/sdcard/LC/compare.jpg");
file.createNewFile();
Bitmap bm = rel.getDrawingCache();
FileOutputStream ostream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.JPEG, 80, ostream);
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}
}