Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int getPixel(Context context, int pixel) { float density = context.getResources().getDisplayMetrics().density; int paddingDp = (int) (pixel * density); return paddingDp; } }