获取设备分辨率两种方法

private TextView textView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
String string = "手机屏幕分辨率为:" + displayMetrics.widthPixels + "x" + displayMetrics.heightPixels;
textView = (TextView) findViewById(R.id.textView);
textView.setText(string);
}






private TextView textView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Display display = getWindowManager().getDefaultDisplay();
String string = "手机的屏幕分辨率为:" + display.getWidth() + "x"
+ display.getHeight();
textView = (TextView) findViewById(R.id.textView);
textView.setText(string);
}
 

你可能感兴趣的:(分辨率)