嗨,朋友们是安卓新手。我创建了一个包含 4 个选项卡的申请表,现在我需要一个布局的屏幕截图,如果它的编辑文本是在单击保存按钮时填充的。是否可以在android中做,如果不是任何格式,但我想要一个带有图像的字段副本
Calendar.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//getScreenViewBitmap(vs);
loadBitmapFromView(vs);
}
});
}
public static RelativeLayout createProgrammeView
(Context context, int width, int height, String title, String time) {
RelativeLayout.LayoutParams params;
RelativeLayout rlv = new RelativeLayout(context);
params = new RelativeLayout.LayoutParams(width, height);
rlv.setLayoutParams(params);
rlv.setPadding(3, 3, 3, 3);
//rlv.setBackgroundResource(R.drawable.background);
TextView tv = new TextView(context);
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
tv.setId(R.id.textView1);
tv.setLayoutParams(params);
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setSingleLine(true);
tv.setEllipsize(TruncateAt.END);
tv.setTextColor(Color.parseColor("#fff"));
tv.setTextSize(11);
tv.setText(title);
rlv.addView(tv);
tv = new TextView(context);
params = new RelativeLayout.LayoutParams(16, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.textView1);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.setMargins(0, 4, 0, 0);
tv.setId(R.id.time);
tv.setLayoutParams(params);
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setSingleLine(true);
tv.setEllipsize(null);
tv.setTextColor(Color.parseColor("#fff"));
tv.setTextSize(10);
tv.setText(time);
rlv.addView(tv);
return rlv;
}
public static Bitmap loadBitmapFromView(RelativeLayout v) {
Bitmap b = Bitmap.createBitmap(582, 136, Bitmap.Config.ARGB_8888);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
System.out.println(b);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "test1111.jpeg");
FileOutputStream fo;
try {
fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(f.exists());
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
嗨,在上面的代码中,它是一个相对布局,我尝试将布局输出作为图像,但它显示空的黑色图像没有任何内容,但它创建了一个文件。此外,当我单击时,布局视图也会发生变化