get Height Ratio - Android User Interface

Android examples for User Interface:Screen Size

Description

get Height Ratio

Demo Code


//package com.java2s;

import android.content.Context;

public class Main {
    private static Context context;
    private static boolean phone;
    private static double heightRatio = 0;

    public static double getHeightRatio() {
        if (heightRatio == 0) {
            heightRatio = getDisplayHeight() / (isPhone() ? 568.0 : 768.0);
        }//from  w w  w  .  j  av a 2  s .c  om
        return heightRatio;
    }

    public static int getDisplayHeight() {
        return context.getResources().getDisplayMetrics().heightPixels;
    }

    public static boolean isPhone() {
        return phone;
    }
}

Related Tutorials