「Android/画面サイズ」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「 // 画面幅サイズ Point point = new Point(); // Android 3.2~ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { WindowManager wm = (WindowMana...」) |
|||
| 行1: | 行1: | ||
| − | // 画面幅サイズ | + | // 画面幅サイズ(ステータスバーを含まない) |
Point point = new Point(); | Point point = new Point(); | ||
// Android 3.2~ | // Android 3.2~ | ||
| 行9: | 行9: | ||
Log.i("test", "x=" + point.x); | Log.i("test", "x=" + point.x); | ||
Log.i("test", "y=" + point.y); | Log.i("test", "y=" + point.y); | ||
| + | |||
| + | // 画面幅サイズ(ステータスバーを含む) | ||
| + | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
| + | // Android 4.2~ | ||
| + | Method getRealSize = Display.class.getMethod("getRealSize", Point.class); | ||
| + | getRealSize.invoke(display, p); | ||
| + | Log.i("test", "width=" + p.x); | ||
| + | Log.i("test", "height=" + p.y); | ||
| + | } | ||
2016年11月4日 (金) 18:33時点における版
// 画面幅サイズ(ステータスバーを含まない)
Point point = new Point();
// Android 3.2~
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
WindowManager wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
disp.getSize(point);
}
Log.i("test", "x=" + point.x);
Log.i("test", "y=" + point.y);
// 画面幅サイズ(ステータスバーを含む)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// Android 4.2~
Method getRealSize = Display.class.getMethod("getRealSize", Point.class);
getRealSize.invoke(display, p);
Log.i("test", "width=" + p.x);
Log.i("test", "height=" + p.y);
}
