The height when the custom View is set to full screen is larger than that obtained by DisplayMetrics.

by using the code:

DisplayMetrics dm = getResources().getDisplayMetrics();
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;

Log.e(TAG, "W = " + dm.widthPixels + ", H = " + dm.heightPixels);

get the width and height of the screen. On the phone I tested, screenWidth = 1440 , screenHeight = 2400 :


View layout_width layout_height match_parent:


onDraw View width height:


:
onDraw  Log

I would like to ask you why and how to solve this inconsistency problem?

Mar.04,2021

if you remember correctly, the first method does not include the height of the status bar

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38271-2c104.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38271-2c104.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?