Android获取屏幕尺寸大小代码实例

Android获取屏幕尺寸大小代码实例_第1张图片

@Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 //获取屏幕的长度和宽度
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int heigh = dm.heightPixels;
    
    Dialog d = new Dialog(this);
    d.setTitle(width + "*" + heigh);
    d.show();
 }

你可能感兴趣的:(Android获取屏幕尺寸大小代码实例)