我需要保存滚动视图及其所有内容,然后通过电子邮件发送。主要问题是保存整个滚动视图,而不仅仅是屏幕上显示的内容。有没有办法保存整个滚动视图,如果有,怎么办?
它位于 scrollView 内的 LinearLayout 中。我正在尝试保存表格,这是我用来保存表格的方法:
public void saveTable(){
View v = findViewById(R.id.all_tables);
v.setDrawingCacheEnabled(true);
TextView title = (TextView)findViewById(R.id.title);
int height = ((ScrollView) v).getChildAt(0).getHeight();
int width =((ScrollView) v).getChildAt(0).getWidth();
v.layout(0, title.getMeasuredHeight(), width, height);
v.buildDrawingCache();
bm = Bitmap.createBitmap(v.getDrawingCache());
try {
file = new File(Environment.getExternalStorageDirectory() + "/CE_Budgets");
if (!file.exists())
file.mkdir();
file = new File(Environment.getExternalStorageDirectory() + "/CE_Budgets/tables.png");
if (!(file.exists())) {
try {
file.createNewFile();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "It didn't work", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
FileOutputStream out = new FileOutputStream(file.getPath());
bm.compress(CompressFormat.PNG, 100, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}