Android获取窗体信息的Util方法
Android获取窗体信息的Util方法,方法很简单,这里就不多废话了,直接上代码
package com.wangyi.tools; import android.app.Activity; import android.util.DisplayMetrics; public class DisplayUtils { private static DisplayUtils instance; private Activity mActivity; private DisplayUtils(Activity mActivity){ this.mActivity=mActivity; } public static DisplayUtils getInstance(Activity mActivity){ if(instance==null){ instance=new DisplayUtils(mActivity); } return instance; } public final int[] getScreenSize(){ int[] size=new int[2]; DisplayMetrics dm = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); size[0]=dm.widthPixels; size[1]=dm.heightPixels; return size; } public final static int getWindowWidth(Activity mActivity) { DisplayMetrics dm = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); return dm.widthPixels; } public final static int getWindowHeight(Activity mActivity) { DisplayMetrics dm = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); return dm.heightPixels; } }
以上所述就是本文的全部内容了,希望大家能够喜欢。
赞 (0)