Returns the size in pixels of an attribute dimension - Android Graphics

Android examples for Graphics:Pixel

Description

Returns the size in pixels of an attribute dimension

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.res.TypedArray;

public class Main {
    /**/*ww w . j a va  2  s.  c o  m*/
     * Returns the size in pixels of an attribute dimension
     *
     * @param context the context to get the resources from
     * @param attr    is the attribute dimension we want to know the size from
     * @return the size in pixels of an attribute dimension
     */
    public static int getThemeAttributeDimensionSize(Context context,
            int attr) {
        TypedArray a = null;
        try {
            a = context.getTheme().obtainStyledAttributes(
                    new int[] { attr });
            return a.getDimensionPixelSize(0, 0);
        } finally {
            if (a != null) {
                a.recycle();
            }
        }
    }
}

Related Tutorials