Android screenshot from code. Got it but not perfect

前端 未结 6 558
攒了一身酷
攒了一身酷 2021-02-04 21:47

I\'m trying to take a screenshot in code in Android. Actually the screenshot is the bitmap of the main RelativeLayout. The screenshot is taken but the content appears wrong, the

6条回答
  •  深忆病人
    2021-02-04 22:16

    I'm assuming you're doing this during creation. Don't!

    use a postDelayed(Runnable, int) to execute the Bitmap bm = Bitmap.createBitmap(v.getDrawingCache()); after the view is drawn.

    also, remove the v.measure() and v.layout() those are methods for the ViewGroup to be calling.

提交回复
热议问题