借鉴网址:
https://www.cnblogs.com/pswzone/archive/2012/03/11/2389993.html
http://blog.csdn.net/gly742279097/article/details/45220819
获取屏幕的四种方法:
1
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
2
WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
3
WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
int height = outMetrics.heightPixels;
4
Resources resources = this.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
float density = dm.density;
int width = dm.widthPixels;
int height = dm.heightPixels;
因为
getDefaultDisplay().getWidth()过时了,推荐3.4
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
listView.measure(w, h);
LinearLayout.measure(w,h);
imgview,button等view都可以
int height = listView.getMeasuredHeight();
Log.e("ee", "page1中listview的高:" + height);
Android开发中dip,dpi,density,px等详解
可以看下他的简书,可能有你想要的信息:
http://www.jianshu.com/p/cd66b7e01d4a