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

内容摘要
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//获取屏幕的
文章正文

@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();
 }

代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!