listview长截图,小米手机和华为手机效果不同。

春华-秋实 春华-秋实 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
通过如下代码进行长截图,在华为手机截图效果正常,但是oppo和小米手机的效果就是不对的。
public static Bitmap shotListView(ListView listview) {

ListAdapter adapter = listview.getAdapter();
int itemscount = adapter.getCount();
int allitemsheight = 0;
int bigbitmapwidth = 0;
List<Bitmap> bmps = new ArrayList<Bitmap>();

for (int i = 0; i < itemscount - 1; i++) {
View childView = adapter.getView(i, null, listview);

childView.measure(
View.MeasureSpec.makeMeasureSpec(listview.getMeasuredWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());
childView.setDrawingCacheEnabled(true);
childView.buildDrawingCache();

bmps.add(childView.getDrawingCache());
allitemsheight += childView.getMeasuredHeight();
}
bigbitmapwidth = listview.getMeasuredWidth();
Bitmap bigbitmap = Bitmap.createBitmap(bigbitmapwidth, allitemsheight, Bitmap.Config.ARGB_8888);
Canvas bigcanvas = new Canvas(bigbitmap);
bigcanvas.drawColor(Color.BLUE);

Paint paint = new Paint();
int iHeight = 0;

for (int i = 0; i < bmps.size(); i++) {
Bitmap bmp = bmps.get(i);
bigcanvas.drawBitmap(bmp, 0, iHeight, paint);
iHeight += bmp.getHeight();
bmp.recycle();
bmp = null;
}
return bigbitmap;
}


华为手机上截图效果:

小米手机上截图效果:

白色部分是我在listview添加的headerview。
蓝色背景是为了查看截图效果添加的。
求大神指点:
1.为什么小米手机上drawbitmap的宽度与测量出来的不同?
2.为什么小米手机上listview第一项和headerview之间还有间隔?
请大神指点,万分感激。
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
春华-秋实
Android 80,490 成员 91,371 内容