android - How to capture invisible content of Tab and Recyclerview in Adroid? -
i have layout contain tablayout , viewpager, have 3 tab.layout code
<android.support.v4.widget.nestedscrollview android:id="@+id/nest_scrollview" android:layout_width="match_parent" android:layout_height="match_parent" android:cliptopadding="false" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.design.widget.tablayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:layout_gravity="bottom" android:background="@color/tab_background" app:tabindicatorcolor="@color/colorprimary" /> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </linearlayout> </android.support.v4.widget.nestedscrollview> now take screen shot, should take tab , it's contain.
i used below code take screen shot, it's take visible part on screen.
public bitmap takescreenshot() { view rootview = findviewbyid(android.r.id.content).getrootview(); rootview.setdrawingcacheenabled(true); return rootview.getdrawingcache(); } public void savebitmap(bitmap bitmap) { imagepath = new file(environment.getexternalstoragedirectory() + "/screenshot.png"); fileoutputstream fos; try { fos = new fileoutputstream(imagepath); bitmap.compress(bitmap.compressformat.jpeg, 100, fos); fos.flush(); fos.close(); } catch (filenotfoundexception e) { log.e("grec", e.getmessage(), e); } catch (ioexception e) { log.e("grec", e.getmessage(), e); } }
you can capture entire recyclerview using below code.
public class utils { public utils() { } public bitmap getscreenshotfromrecyclerview(recyclerview view) { bitmap bigbitmap = null; recyclerview.adapter adapter = view.getadapter(); if (adapter != null) { int size = adapter.getitemcount(); int height = 0; paint paint = new paint(); int iheight = 0; final int maxmemory = (int) (runtime.getruntime().maxmemory() / 1024); // use 1/8th of available memory memory cache. final int cachesize = maxmemory / 8; lrucache<string, bitmap> bitmacache = new lrucache<>(cachesize); (int = 0; < size; i++) { recyclerview.viewholder holder = adapter.createviewholder(view, adapter.getitemviewtype(i)); adapter.onbindviewholder(holder, i); 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()); holder.itemview.setdrawingcacheenabled(true); holder.itemview.builddrawingcache(); bitmap drawingcache = holder.itemview.getdrawingcache(); if (drawingcache != null) { bitmacache.put(string.valueof(i), drawingcache); } // holder.itemview.setdrawingcacheenabled(false); // holder.itemview.destroydrawingcache(); height += holder.itemview.getmeasuredheight(); } bigbitmap = bitmap.createbitmap(view.getmeasuredwidth(), height, bitmap.config.argb_8888); canvas bigcanvas = new canvas(bigbitmap); bigcanvas.drawcolor(color.white); (int = 0; < size; i++) { bitmap bitmap = bitmacache.get(string.valueof(i)); bigcanvas.drawbitmap(bitmap, 0f, iheight, paint); iheight += bitmap.getheight(); bitmap.recycle(); } } storeimage(bigbitmap, "myrecipetest.jpg"); return bigbitmap; } /** * convert bitmap image , save sdcard. * * @param imagedata -bitmap image. * @param filename -name of image. * @return */ public boolean storeimage(bitmap imagedata, string filename) { // path external storage (sd card) file sdiconstoragedir = new file(environment.getexternalstoragedirectory() .getabsolutepath() + "/myappdir/"); // create storage directories, if don't exist sdiconstoragedir.mkdirs(); try { string filepath = sdiconstoragedir.tostring() + file.separator + filename; fileoutputstream fileoutputstream = new fileoutputstream(filepath); bufferedoutputstream bos = new bufferedoutputstream(fileoutputstream); log.e("<== share ==>", "storeimage: image saved at----" + filepath); // choose format if png doesn't suit imagedata.compress(bitmap.compressformat.png, 100, bos); bos.flush(); bos.close(); } catch (filenotfoundexception e) { log.w("tag", "error saving image file: " + e.getmessage()); return false; } catch (ioexception e) { log.w("tag", "error saving image file: " + e.getmessage()); return false; } return true; } }
Comments
Post a Comment