Android获取窗体信息的Util方法
程序员文章站
2023-11-13 23:56:52
android获取窗体信息的util方法,方法很简单,这里就不多废话了,直接上代码
package com.wangyi.tools;
import and...
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; } }
以上所述就是本文的全部内容了,希望大家能够喜欢。