Search out, many are not working, the width and height of the wrong.

Here is no more nonsense to say, to a current view of the most useful. Directly on the code:

* @return Returns an Array */ private fun getScreen(context: context): IntArray { var mRealSizeWidth = 0 var mRealSizeHeight = 0 val display = (context.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay val outPoint = Point() if (Build.VERSION.SDK_INT >= 19) { // include navigation bar display.getRealSize(outPoint) } else { // exclude navigation bar display.getSize(outPoint) } if (outPoint.y > outPoint.x) { mRealSizeHeight = outPoint.y mRealSizeWidth = outPoint.x } else { mRealSizeHeight = outPoint.x mRealSizeWidth = outPoint.y } return intArrayOf(mRealSizeWidth, mRealSizeHeight) }Copy the code