/** * 截取scrollview的屏幕 * * @param * @return */ public Bitmap getBitmapByView(NestedScrollView v) { if (null == v) { return null; } v.setDrawingCacheEnabled(true); v.buildDrawingCache(); v.measure(View.MeasureSpec.makeMeasureSpec(v.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec( v.getHeight(), View.MeasureSpec.AT_MOST)); v.layout((int) v.getX(), (int) v.getY(), (int) v.getX() + v.getMeasuredWidth(), (int) v.getY() + v.getMeasuredHeight()); int h = 0; for (int i = 0; i < v.getChildCount(); i++) { h += v.getChildAt(i).getHeight(); v.getChildAt(i).setBackgroundColor(Color.parseColor("#FFC130")); } bitmap = Bitmap.createBitmap(v.getWidth(), h, Bitmap.Config.RGB_565); final Canvas canvas = new Canvas(bitmap); v.draw(canvas); // Bitmap b = Bitmap.createBitmap(v.getDrawingCache(), 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.setDrawingCacheEnabled(false); v.destroyDrawingCache(); return bitmap; }
NestedScrollView 嵌套RecyclerView 截图
最新推荐文章于 2023-07-18 18:58:46 发布