Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

截图工具类 #20

Closed
TrueloveSomeGIRl opened this issue Dec 17, 2020 · 2 comments
Closed

截图工具类 #20

TrueloveSomeGIRl opened this issue Dec 17, 2020 · 2 comments

Comments

@TrueloveSomeGIRl
Copy link

CapturePictureUtils 截图工具类截图Recyclerview的时候 如果item 里面有自定义view+动画 截图下来动画初始值一直未0
请问这个有没有解决办法 谢谢
image

@afkT
Copy link
Owner

afkT commented Dec 17, 2020

看描述猜测,应该是存在动画且没绘制导致,你可以这样尝试下解决

CapturePictureUtils#snapshotByRecyclerView_LinearLayoutManager

新建一个类,复制该方法代码,并且进行修改 竖屏 的代码

// ===========
// = 竖向滑动 =
// ===========

for (int i = 0; i < itemCount; i++) {
    RecyclerView.ViewHolder holder = adapter.createViewHolder(recyclerView, adapter.getItemViewType(i));
    adapter.onBindViewHolder(holder, i);
    View childView = holder.itemView;
    WidgetUtils.measureView(childView, recyclerView.getWidth());
    bitmaps[i] = canvasBitmap(childView, config);
    height += childView.getMeasuredHeight();
}

修改为自己的 Adapter 并且新增自定义方法,自定义方法主要的作用是对 holder.itemView 里面的动画 View 进行直接赋值并且不做动画效果,且调用 postInvalidate。

这样就能够实现,截图走无动画且进行绘制,非截图则有动画,你看下这样的思路能否正常截出来

@afkT
Copy link
Owner

afkT commented Dec 17, 2020

看描述猜测,应该是存在动画且没绘制导致,你可以这样尝试下解决

CapturePictureUtils#snapshotByRecyclerView_LinearLayoutManager

新建一个类,复制该方法代码,并且进行修改 竖屏 的代码

// ===========
// = 竖向滑动 =
// ===========

for (int i = 0; i < itemCount; i++) {
    RecyclerView.ViewHolder holder = adapter.createViewHolder(recyclerView, adapter.getItemViewType(i));
    adapter.onBindViewHolder(holder, i);
    View childView = holder.itemView;
    WidgetUtils.measureView(childView, recyclerView.getWidth());
    bitmaps[i] = canvasBitmap(childView, config);
    height += childView.getMeasuredHeight();
}

修改为自己的 Adapter 并且新增自定义方法,自定义方法主要的作用是对 holder.itemView 里面的动画 View 进行直接赋值并且不做动画效果,且调用 postInvalidate。

这样就能够实现,截图走无动画且进行绘制,非截图则有动画,你看下这样的思路能否正常截出来

例:adapter.xxxMethod(childView, adapter.getItemViewType(i)) 这样就能够知道属于什么 viewType

@afkT afkT closed this as completed Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants