方法一: public static int SCREEN_WIDTH; public static int SCREEN_HEIGHT; //获取屏幕 WindowManager wm = (WindowManager) getBaseContext().getSystemService( Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.ge…
试过在OnCreate()中获取控件高度与宽度的童鞋都知道,getWidth()与getHeight()方法返回是0,具体原因 看一下Activity的生命周期 就会明白. 上代码: 方法一: int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED…
dip(dp): device independent pixels(设备独立像素) dip,就是把屏幕的高分成480分,宽分成320分.比如你做一条160dip的横线,无论你在320还480的模拟器上,都是一半屏的长度. dpi:dot per inch dpi=(√(横向分辨率^2+纵向分辨率^2))/屏幕尺寸) ppi:pixels per inch(跟dpi一样) 计算了一下小米手机屏幕的PPI,4.0英寸.分辨率854X480,PPI(DPI) =√(854^2+480^2)/4=…