Taking a “screenshot” of a specific layout in Android

后端 未结 6 2016
天命终不由人
天命终不由人 2020-11-30 03:26

I have two main issues which are closely linked. I am looking at these problems from a programmatic point of view.

(1) - I wish to take a screenshot of the

6条回答
  •  情话喂你
    2020-11-30 04:07

    Here is the exact solution you want, It will display entire screen including content hidden in your ScrollView

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    FrameLayout root = (FrameLayout) inflater.inflate(R.layout.activity_main, null); // activity_main is UI(xml) file we used in our Activity class. FrameLayout is root view of my UI(xml) file.
    root.setDrawingCacheEnabled(true);
    Bitmap bitmap = getBitmapFromView(this.getWindow().findViewById(R.id.frameLayout)); // here give id of our root layout (here its my FrameLayout's id)
    

    Display bitmap in your ImageView or use it as you want.
    Enjoy..

提交回复
热议问题