Java tutorial
//package com.java2s; import android.content.Context; import android.util.TypedValue; public class Main { /** * dp to px * @param dip * @param context * @return */ public static int dipTopx(float dip, Context context) { int num = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics()); return num; } }