背景
new一个有各种信息的View,不需要显示给用户,对这个View截图。上传分享等…
代码实现
ViewUtils.layoutView(view, 290, 210);
需要放在所有子view都bind完成后再调用,否则界面会乱掉- 用ConstraintLayout布局,call
ViewUtils.layoutView(view, 290, 210);
整个页面也乱掉 - 由于界面不可见截图保存时mAttatch==null,Bitmap只能是
565
格式会丢失渐变背景
,测试一种有效的方式是将view add 到一个父控中如:getWindow().getDecorView().addView(x);
public static void layoutView(View v, int width, int height) {
// validate view.width and view.height
v.layout(0, 0, width, height);
int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
// validate view.meas