Resolves a dimension resource that uses scaled pixels - Android Graphics

Android examples for Graphics:Pixel

Description

Resolves a dimension resource that uses scaled pixels

Demo Code


//package com.book2s;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.DimenRes;

public class Main {
    /**/* w  w  w . j  a  va  2 s .c o  m*/
     * Resolves a dimension resource that uses scaled pixels
     *
     * @param context the current context
     * @param sizeRes the dimension resource holding an SP value
     * @return the text size in pixels
     */
    public static float pixelsFromSpResource(Context context,
            @DimenRes int sizeRes) {
        final Resources res = context.getResources();
        return res.getDimension(sizeRes) / res.getDisplayMetrics().density;
    }
}

Related Tutorials