/**
* 支持 ScrollView ViewGroup ListView RecyclerView NestedScrollView
* 长截图
*
* @param rootView
* @return
*/
public Bitmap getViewBitmap(View rootView) {
int h = 0;
Bitmap bitmap;
if (rootView instanceof ScrollView) {
h = ((ScrollView) rootView).getChildAt(0).getHeight();
Log.i(TAG, "rootView is ScrollView");
} else if (rootView instanceof NestedScrollView) {
h = ((NestedScrollView) rootView).getChildAt(0).getHeight();
Log.i(TAG, "rootView is NestedScrollView");
} else if (rootView instanceof ListView) {
Log.i(TAG, "rootView is ListView");
ListView listView = (ListView) rootView;
for (int i = 0; i < listView.getChildCount(); i++) {
h += listView.getChildAt(i).getHeight();
}
} else if (rootView instanceof RecyclerView) {
Log.i(TAG, "rootView is RecyclerView");
RecyclerView recyclerView = (RecyclerView) rootView;
for (int i = 0; i < recyclerView.getChildCount(); i++) {
h += recyclerView.getChildAt(i).getHeight();
}
} else if (rootView instanceof ViewGroup) {
Log.i(TAG, "rootView is ViewGroup");
h = rootView.getHeight();
}
bitmap = Bitmap.createBitmap(rootView.getWidth(), h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
rootView.draw(canvas);
return bitmap;
}
支持 ScrollView ViewGroup ListView RecyclerView NestedScrollView长截图
最新推荐文章于 2023-08-23 14:51:53 发布