【发布时间】:2014-09-16 08:23:53
【问题描述】:
我有一个 LinearLayout,我想将该视图的内容保存为图像。我已经完成了一半。
File imageFile;
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/a.png";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
Bitmap bitmap;
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 10, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
使用上面的代码,它将保存视图的副本,但仅保存在设备屏幕上看到的内容。我有更多关于我想要保存的视图的信息。上面来自here 和this 的代码只会将屏幕上看到的信息保存为图像。我希望保存所有信息,即使是不在屏幕上的信息(您需要滚动查看)。
我怎样才能做到这一点?
【问题讨论】:
-
"你需要滚动才能看到的地方" -- 滚动什么?
ListView?GridView?ScrollView?WebView?MapView?还有什么? -
查看其余信息。它是一个线性布局内的表格视图
-
您不能滚动“线性布局内的表格视图”。然而你声称你缺少的是“你需要滚动才能看到的地方”。
-
你可以将 clipChildren 设置为 false 到父视图
-
@commonsware,有一个列表视图填充该表视图(我的消息由于某种原因被切断)。
标签: android android-linearlayout