get Width Ratio - Android User Interface

Android examples for User Interface:Screen Size

Description

get Width Ratio

Demo Code


//package com.java2s;

import android.content.Context;

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

    public static double getWidthRatio() {
        if (widthRatio == 0) {
            widthRatio = getDisplayWidth() / (isPhone() ? 320.0 : 1024.0);
        }//w w w . j a va 2  s.co  m
        return widthRatio;
    }

    public static int getDisplayWidth() {
        return context.getResources().getDisplayMetrics().widthPixels;
    }

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

Related Tutorials