Get screen width and height in Android

前端 未结 30 4053
野的像风
野的像风 2020-11-22 09:28

How can I get the screen width and height and use this value in:

@Override protected void onMeasure(int widthSpecId, int heightSpecId) {
    Log.e(TAG, \"onM         


        
30条回答
  •  迷失自我
    2020-11-22 10:08

    I found weigan's answer best one in this page, here is how you can use that in Xamarin.Android:

    public int GetScreenWidth()
    {
        return Resources.System.DisplayMetrics.WidthPixels;
    }
    
    public int GetScreenHeight()
    {
        return Resources.System.DisplayMetrics.HeightPixels;
    }
    

提交回复
热议问题