Android How to - Get Screen Height








Question

We would like to know how to get Screen Height.

Answer

//from  w  ww.j a  v a2  s. c om
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class Main {

  public static int getScreenHeight(Context context) {
    DisplayMetrics metric = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metric);
    return metric.heightPixels;
  }

}