calculate Screen Size - Android Phone

Android examples for Phone:Screen

Description

calculate Screen Size

Demo Code


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

import android.util.DisplayMetrics;

public class Main {
    public static double calculateScreenSize(DisplayMetrics outMetrics) {
        double x = Math.pow(outMetrics.widthPixels / outMetrics.xdpi, 2);
        double y = Math.pow(outMetrics.heightPixels / outMetrics.ydpi, 2);
        double screenInches = Math.sqrt(x + y);
        return screenInches;
    }/*  www. j  a  v a 2 s . com*/

    public static double calculateScreenSize(Context context) {
        DisplayMetrics outMetrics = context.getResources()
                .getDisplayMetrics();
        return calculateScreenSize(outMetrics);
    }
}

Related Tutorials