public class MainActivity extends Activity{
float screenWidth;
float screenHeight;
Display display;
Point size;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = getWindowManager().getDefaultDisplay();
size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
}
如果不是在Activity中(比如在View中需要得到)以上数据时,无法直接getWimdowManager()得到WimdowManager,可以通过
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
之后完全一致。