resolve Dimension from Context - Android android.content

Android examples for android.content:Context

Description

resolve Dimension from Context

Demo Code


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

import android.content.res.TypedArray;

import android.support.annotation.AttrRes;

public class Main {
    public static int resolveDimension(Context context, @AttrRes int attr) {
        return resolveDimension(context, attr, -1);
    }/*from w  ww .ja va2  s.c om*/

    private static int resolveDimension(Context context, @AttrRes int attr,
            int fallback) {
        TypedArray a = context.getTheme().obtainStyledAttributes(
                new int[] { attr });
        try {
            return a.getDimensionPixelSize(0, fallback);
        } finally {
            a.recycle();
        }
    }
}

Related Tutorials