Skip to content

Instantly share code, notes, and snippets.

@hamakn
Created April 20, 2015 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamakn/bab12c4348b1d95bffa9 to your computer and use it in GitHub Desktop.
Save hamakn/bab12c4348b1d95bffa9 to your computer and use it in GitHub Desktop.
DisplayMetrics#widthPixels の値が機種とデバイスの向きによって変わる
# screen orientationは固定
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
Log.d("metrics.widthPixels: " + metrics.widthPixels);
# SONY SO-02g Android 4.4.4
# => デバイスが縦向きでも横向きでも metrics.widthPixels の値は同じ
# Samsung SC-02f Android 4.4.2
# => デバイスが縦向きか横向きかで metrics.widthPixels の値が変わる(Heightと入れ替わる)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment