shotHeight += footHight;
//返回到顶部
while (mRecyclerView.canScrollVertically(-1)) {
mRecyclerView.scrollBy(0, -oneScreenHeight);
}
//绘制截图的背景
final Bitmap bigBitmap = Bitmap.createBitmap(mRecyclerView.getMeasuredWidth(), shotHeight, Bitmap.Config.ARGB_8888);
final Canvas bigCanvas = new Canvas(bigBitmap);
Drawable lBackground = mRecyclerView.getBackground();
if (lBackground instanceof ColorDrawable) {
ColorDrawable lColorDrawable = (ColorDrawable) lBackground;
int lColor = lColorDrawable.getColor();
bigCanvas.drawColor(lColor);
}
final int[] drawOffset = {0};
final Canvas canvas = new Canvas();
if (shotHeight <= oneScreenHeight) {
//仅有一页
Bitmap bitmap = Bitmap.createBitmap(mRecyclerView.getWidth(), mRecyclerView.getHeight(), Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
mRecyclerView.draw(canvas);
if (callBack != null)
callBack.onRecFinished(bitmap);
} else {
//超过一页
final int finalShotHeight = shotHeight;
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if ((drawOffset[0] + oneScreenHeight < finalShotHeight)) {
//超过一屏
Bitmap bitmap = Bitmap.createBitmap(mRecyclerView.getWidth(), mRecyclerView.getHeight(), Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
mRecyclerView.draw(canvas);
bigCanvas.drawBitmap(bitmap, 0, drawOffset[0], paint);
drawOffset[0] += oneScreenHeight;
mRecyclerView.scrollBy(0, oneScreenHeight);
try {
bitmap.recycle();
} catch (Exception ex) {
ex.printStackTrace();
}
mRecyclerView.postDelayed(this, 10);
} else {
//不足一屏时的处理
int leftHeight = finalShotHeight - drawOffset[0] - footHight;
mRecyclerView.scrollBy(0, leftHeight);
int top = oneScreenHeight - (finalShotHeight - drawOffset[0]);
if (top > 0 && leftHeight > 0) {
Bitmap bitmap = Bitmap.createBitmap(mRecyclerView.getWidth(), mRecyclerView.getHeight(), Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
mRecyclerView.draw(canvas);
//截图,只要补足的那块图
bitmap = Bitmap.createBitmap(bitmap, 0, top, bitmap.getWidth(), leftHeight, null, false);
bigCanvas.drawBitmap(bitmap, 0, drawOffset[0], paint);
try {
bitmap.recycle();
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (callBack != null)
callBack.onRecFinished(bigBitmap);
}