小方法
1.获取屏幕分辨率:
1 public class BaseTools { 2 3 public static int getWindowWidth(Context context) { 4 // 获取屏幕分辨率 5 WindowManager wm = (WindowManager) (context 6 .getSystemService(Context.WINDOW_SERVICE)); 7 DisplayMetrics dm = new DisplayMetrics(); 8 wm.getDefaultDisplay().getMetrics(dm); 9 int mScreenWidth = dm.widthPixels; 10 return mScreenWidth; 11 } 12 13 public static int getWindowHeigh(Context context) { 14 // 获取屏幕分辨率 15 WindowManager wm = (WindowManager) (context 16 .getSystemService(Context.WINDOW_SERVICE)); 17 DisplayMetrics dm = new DisplayMetrics(); 18 wm.getDefaultDisplay().getMetrics(dm); 19 int mScreenHeigh = dm.heightPixels; 20 return mScreenHeigh; 21 } 22 }
android 小方法
时间: 2024-12-26 13:50:17