Conversion from DIPs (Density-independent pixels) to pixels - Android Graphics

Android examples for Graphics:Pixel

Description

Conversion from DIPs (Density-independent pixels) to pixels

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.res.Resources;

public class Main {
    /**/*from  w ww.java2 s  .  c  o m*/
     * Conversion from DIPs (Density-independent pixels) to pixels
     * @param context
     * @param dip
     * @return
     */
    public static int convertDipsToPixels(Context context, int dip) {
        Resources resources = context.getResources();
        float pixelValue = (dip * resources.getDisplayMetrics().density);
        resources = null;
        return (int) pixelValue;
    }
}

Related Tutorials