get Screen Dimension Dp - Android User Interface

Android examples for User Interface:Screen Size

Description

get Screen Dimension Dp

Demo Code


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

import android.util.DisplayMetrics;
import android.util.Pair;

public class Main {
    public static Pair<Float, Float> getScreenDimensDp(Context context) {
        DisplayMetrics displayMetrics = context.getResources()
                .getDisplayMetrics();//ww  w  .  j a v  a  2s .  c o m
        float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
        float dpHeight = displayMetrics.heightPixels
                / displayMetrics.density;
        return new Pair(dpWidth, dpHeight);
    }
}

Related Tutorials