get Current Screen Height Inches - Android User Interface

Android examples for User Interface:Screen Size

Description

get Current Screen Height Inches

Demo Code


//package com.java2s;
import android.content.Context;

import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class Main {
    public static double getCurrentScreenHeightInches(Context context) {
        DisplayMetrics dm = getDisplayMetrics(context);
        return dm.heightPixels / dm.ydpi;
    }/*  ww w.  j  a  v a  2  s  .co m*/

    private static DisplayMetrics getDisplayMetrics(Context context) {
        DisplayMetrics dm = new DisplayMetrics();
        getDefaultDisplay(context).getMetrics(dm);
        return dm;
    }

    private static Display getDefaultDisplay(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay();
    }
}

Related Tutorials