Java tutorial
//package com.java2s; import android.content.Context; public class Main { /** * Get dependent pixel. * * @param dp dependent pixel for convert. * @return number of dependent pixel. */ public static int getDependentPixel(int dp, Context context) { float scale = context.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); } }