Android获取窗体信息的Util方法
Android获取窗体信息的Util方法,方法很简单,这里就不多废话了,直接上代码
packagecom.wangyi.tools; importandroid.app.Activity; importandroid.util.DisplayMetrics; publicclassDisplayUtils{ privatestaticDisplayUtilsinstance; privateActivitymActivity; privateDisplayUtils(ActivitymActivity){ this.mActivity=mActivity; } publicstaticDisplayUtilsgetInstance(ActivitymActivity){ if(instance==null){ instance=newDisplayUtils(mActivity); } returninstance; } publicfinalint[]getScreenSize(){ int[]size=newint[2]; DisplayMetricsdm=newDisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); size[0]=dm.widthPixels; size[1]=dm.heightPixels; returnsize; } publicfinalstaticintgetWindowWidth(ActivitymActivity){ DisplayMetricsdm=newDisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); returndm.widthPixels; } publicfinalstaticintgetWindowHeight(ActivitymActivity){ DisplayMetricsdm=newDisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); returndm.heightPixels; } }
以上所述就是本文的全部内容了,希望大家能够喜欢。