Java tutorial
//package com.java2s; /** * Project: warnme-app * File: AppUtils.java * License: * This file is licensed under GNU General Public License version 3 * http://www.gnu.org/licenses/gpl-3.0.txt * * Copyright: Bartosz Cichecki [ cichecki.bartosz@gmail.com ] * Date: 29-12-2012 */ import android.content.Context; import android.content.res.Resources; import android.util.DisplayMetrics; public class Main { public static float convertDpToPixel(Context context, float dp) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px; } }