日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

记录一下Android 长截屏功能

發布時間:2023/12/10 Android 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 记录一下Android 长截屏功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

需求對webview進行截屏,可以大于一屏

代碼:

在setContentView之前調用

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {WebView.enableSlowWholeDocumentDraw();}

對大于5.0的版本處理,防止截屏不全。

public static Bitmap capture(WebView webView) {Picture picture = webView.capturePicture();int width = picture.getWidth();int height = picture.getHeight();Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bitmap);picture.draw(canvas);return bitmap;}

擴展:截屏listview,scrollview

/*** 截取scrollview的屏幕* **/public static Bitmap getScrollViewBitmap(ScrollView scrollView) {int h = 0;Bitmap bitmap;for (int i = 0; i < scrollView.getChildCount(); i++) {h += scrollView.getChildAt(i).getHeight();}// 創建對應大小的bitmapbitmap = Bitmap.createBitmap(scrollView.getWidth(), h,Bitmap.Config.ARGB_8888);final Canvas canvas = new Canvas(bitmap);scrollView.draw(canvas);return bitmap;} //截取超過一屏的listviewpublic static Bitmap shotListView(ListView listview) {ListAdapter adapter = listview.getAdapter();int itemscount = adapter.getCount();int allitemsheight = 0;List<Bitmap> bmps = new ArrayList<Bitmap>();for (int i = 0; i < itemscount; i++) {View childView = adapter.getView(i, null, listview);childView.measure(View.MeasureSpec.makeMeasureSpec(listview.getWidth(), 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();}int w = listview.getMeasuredWidth();Bitmap bigbitmap = Bitmap.createBitmap(w, allitemsheight, Bitmap.Config.ARGB_8888);Canvas bigcanvas = new Canvas(bigbitmap);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

/*** 截圖listview* **/public static Bitmap getListViewBitmap(ListView listView,String picpath) {int h = 0;Bitmap bitmap;// 獲取listView實際高度for (int i = 0; i < listView.getChildCount(); i++) {h += listView.getChildAt(i).getHeight();}Log.d(TAG, "實際高度:" + h);Log.d(TAG, "list 高度:" + listView.getHeight());// 創建對應大小的bitmapbitmap = Bitmap.createBitmap(listView.getWidth(), h,Bitmap.Config.ARGB_8888);final Canvas canvas = new Canvas(bitmap);listView.draw(canvas);return bitmap;}

總結

以上是生活随笔為你收集整理的记录一下Android 长截屏功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。