Java tutorial
//package com.java2s; import android.content.Context; import android.util.TypedValue; public class Main { /** * Function to convert the given size in dp. * @param mContext context of the activity. * @param iValue value the needed to be changed. * @return value in dp */ public static int getSizeInDp(Context mContext, int iValue) { return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, iValue, mContext.getResources().getDisplayMetrics())); } }