Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.content.Context; public class Main { private static int getIdealSizeFromResourceInDp(Context context, int resource) { float sizeInPx = context.getResources().getDimension(resource); float density = context.getResources().getDisplayMetrics().density; return Math.round(sizeInPx / density); } }