Android examples for Graphics:Pixel
Conversion from pixels to DIPs (Density-independent pixels)
//package com.java2s; import android.content.Context; import android.content.res.Resources; import android.util.TypedValue; public class Main { /**/*from ww w . ja v a2 s . c o m*/ * Conversion from pixels to DIPs (Density-independent pixels) * @param context * @param pixels * @return */ public static int convertPixelsToDips(Context context, int pixels) { Resources resources = context.getResources(); float dipValue = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, pixels, resources.getDisplayMetrics()); resources = null; return (int) dipValue; } }