Androidの携帯電話の画面の幅の高さを取得する5つの方法
1231 ワード
public class DisplaySizeUtil {
public static Point getDisplaySizeInfo(Context context) {
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Point sizePoint = new Point();
display.getSize(sizePoint);
int width1 = sizePoint.x;
int height1 = sizePoint.y;
int width2 = manager.getDefaultDisplay().getWidth();
int height2 = manager.getDefaultDisplay().getHeight();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width3 = outMetrics.widthPixels;
int height3 = outMetrics.heightPixels;
Resources resources = context.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
float density = dm.density;
int width4 = dm.widthPixels;
int height4 = dm.heightPixels;
Activity activity = new Activity();
WindowManager wm1 = activity.getWindowManager();
int width5 = wm1.getDefaultDisplay().getWidth();
int height5 = wm1.getDefaultDisplay().getHeight();
return sizePoint;
}
}