gpt4 book ai didi

android - 以完整长度截取 RecyclerView 的屏幕截图.. 每个项目都有一个列表

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:59:18 26 4
gpt4 key购买 nike

我正在使用具有动态大小列表的 recyclerView ......当我使用此方法截取每个 recyclerView 项目的屏幕截图时......它截取屏幕截图但每个项目仅包含一个列表项目......即使列表项目 大小 > 1

public static Bitmap getRecyclerViewScreenshot(RecyclerView view) {
int size = view.getAdapter().getItemCount();
RecyclerView.ViewHolder holder = view.getAdapter().createViewHolder(view, 0);
view.getAdapter().onBindViewHolder(holder, 0);
ArrayList<Bitmap> bitmaps=new ArrayList<>();
holder.itemView.measure(View.MeasureSpec.makeMeasureSpec(view.getWidth(),
View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
holder.itemView.layout(0, 0, holder.itemView.getMeasuredWidth(), holder.itemView.getMeasuredHeight());
Bitmap bigBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), holder.itemView.getMeasuredHeight() * size,
Bitmap.Config.ARGB_8888);
Canvas bigCanvas = new Canvas(bigBitmap);
bigCanvas.drawColor(Color.WHITE);
Paint paint = new Paint();
int iHeight = 0;
holder.itemView.setDrawingCacheEnabled(true);
holder.itemView.buildDrawingCache();
bigCanvas.drawBitmap(holder.itemView.getDrawingCache(), 0f, iHeight, paint);
holder.itemView.setDrawingCacheEnabled(false);
holder.itemView.destroyDrawingCache();
iHeight += holder.itemView.getMeasuredHeight();
for (int i = 1; i < size; i++) {
view.getAdapter().onBindViewHolder(holder, i);
holder.itemView.setDrawingCacheEnabled(true);
holder.itemView.buildDrawingCache();
bitmaps.add(holder.itemView.getDrawingCache());
bigCanvas.drawBitmap(holder.itemView.getDrawingCache(), 0f, iHeight, paint);
iHeight += holder.itemView.getMeasuredHeight();
holder.itemView.setDrawingCacheEnabled(false);
holder.itemView.destroyDrawingCache();
}
return bigBitmap;
}



Here is my screenshot attached (`of each item of recyclerView`)!! It should show `two items` but uniformly its showing `1 item` each ` I am facing problem with the `inner listView`

Original 是:- enter image description here

截图 是:- enter image description here

对于每个 recycler item 截图都是这样,只显示 1 项目。

最佳答案

遇到同样的问题并使用这段代码解决了这个问题。

首先,要求您的 View 计算它的测量值,然后要求 View 提供 MeasuredHeight 并完成所有操作。

recyclerView.measure(
View.MeasureSpec.makeMeasureSpec(recyclerView.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

Bitmap bm = Bitmap.createBitmap(recyclerView.getWidth(), recyclerView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
recyclerView.draw(new Canvas(bm));

saveImage(bm);
ImageView im
= new ImageView(getActivity());
im.setImageBitmap(bm);
new AlertDialog.Builder(getActivity()).setView(im).show();

关于android - 以完整长度截取 RecyclerView 的屏幕截图.. 每个项目都有一个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48149291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com