做分享,点击按钮直接通过view生成bitmap,view不展示
public static Bitmap createBitmap3(View v, int width, int height) {
//测量使得view指定大小
int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
v.measure(measuredWidth, measuredHeight);
//调用layout方法布局后,可以得到view的尺寸大小
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap bmp = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
c.drawColor(Color.WHITE);
v.draw(c);
return bmp;
}
使用:
mRootView = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
//这里传值屏幕宽高,得到的视图即全屏大小
createBitmap3(mRootView, getScreenWidth(), getScreenHeight());
生成scrollview的bitmap点下方链接
转载:https://www.cnblogs.com/taixiang/p/9575195.html