/**
* 截屏scrollview成bitmap
* @param scrollView
* @return
*/
public static Bitmap shotScrollView(ScrollView scrollView,String picpath) {
int h = 0;
Bitmap bitmap = null;
for (int i = 0; i < scrollView.getChildCount(); i++) {
h += scrollView.getChildAt(i).getHeight();
}
bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.RGB_565);
final Canvas canvas = new Canvas(bitmap);
scrollView.draw(canvas);
// 测试输出
FileOutputStream out = null;
try {
out = new FileOutputStream(picpath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
if (null != out) {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
} catch (IOException e) {
}
return bitmap;
}
1.该方法对于普通的scrollview生成bitmap长截图可用,对于recycleview,listview 存在复用的view需要模拟滚动截图
2.关于控件宽高获取,不能再oncreat()方法直接执行,因为这个时候图形还没有绘制出来,会直接报空。