Android中获得屏幕的尺寸

类:DispalyMetrics

 文档中的说明:

A structure describing general information about a display, such as its size, density, and font scaling.

例子:

DisplayMetrics metrics = new DisplayMetrics();
 getWindowManager
().getDefaultDisplay().getMetrics(metrics);

 

获得屏幕的大小并且显示

 

//得到屏幕尺寸并且显示

 tvScreenSize = (TextView) findViewById(R.id.tvScreenSize);

//DisplayMetrics对象

DisplayMetrics dm = new DisplayMetrics();

//获得dm

getWindowManager().getDefaultDisplay().getMetrics(dm);

int width = dm.widthPixels;

int height = dm.heightPixels;

       

tvScreenSize.setText(width + " * " + height);

 

你可能感兴趣的:(android)