calculate Screen Size - Android User Interface

Android examples for User Interface:Screen Size

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;
    }// ww  w .ja  v  a  2 s .  co m

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

Related Tutorials