Android examples for User Interface:Screen Orientation
get Screen Height from orientation
//package com.java2s; import android.content.Context; import android.content.res.Configuration; import android.util.DisplayMetrics; import android.util.Log; import android.view.WindowManager; public class Main { public static final String TAG = "CLDeviceUtil"; public static int getScreenHeight(Context context) { int screenSizeOne = -1; int screenSizeTwo = -1; if (screenSizeOne <= 0 || screenSizeTwo <= 0) { DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); screenSizeOne = dm.widthPixels; screenSizeTwo = dm.heightPixels; }/* ww w. j a v a 2 s. c o m*/ Configuration conf = context.getResources().getConfiguration(); switch (conf.orientation) { case Configuration.ORIENTATION_LANDSCAPE: return screenSizeOne < screenSizeTwo ? screenSizeOne : screenSizeTwo; case Configuration.ORIENTATION_PORTRAIT: return screenSizeOne > screenSizeTwo ? screenSizeOne : screenSizeTwo; default: Log.e(TAG, "can't get screen height!"); } return screenSizeOne; } }