Calculates the number of pixels corresponding to the given device independent pixels for the current device. - Android Graphics

Android examples for Graphics:Pixel

Description

Calculates the number of pixels corresponding to the given device independent pixels for the current device.

Demo Code


//package com.java2s;
import android.content.Context;
import android.util.TypedValue;

public class Main {
    private static Context sContext;

    /**//from   w  w w . java2  s . c  o  m
     * Calculates the number of pixels corresponding to the given device independent pixels for the current device.
     * 
     * @param aDp
     *            The number of device independent pixels to transform.
     * @return the number of pixels that corresponds to the given value.
     */
    public static int calcPx(final int aDp) {
        return Math.round(TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, aDp, sContext.getResources()
                        .getDisplayMetrics()));
    }
}

Related Tutorials