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

Menu