get Dimension In Dp - Android User Interface

Android examples for User Interface:Screen Resolution

Description

get Dimension In Dp

Demo Code


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

import android.support.annotation.DimenRes;

public class Main {
    public static int getDimensionInDp(Context context,
            @DimenRes int dimenResId) {
        return (int) (context.getResources().getDimension(dimenResId) / context
                .getResources().getDisplayMetrics().density);
    }//from   ww w .java 2 s .c om
}

Related Tutorials