Вот такая вот проблемка. Есть ресурсник:
Код: Выделить всё
<dimen name="dp">10dp</dimen>
<dimen name="sp">10sp</dimen>Код: Выделить всё
getResources().getDimension(R.dimen.dp);
getResources().getDimension(R.dimen.sp);Код: Выделить всё
private static final String PATTERN_REGEXP = "[0-9]*\\.?[0-9]";
public static float getDimen(Resources resources, int resName)
{
float value = 0;
String sName = null;
try {
sName = resources.getString(resName);
Pattern pattern = Pattern.compile(PATTERN_REGEXP);
Matcher matcher = pattern.matcher(sName);
if (matcher.find()) {
value = Float.valueOf(matcher.group());
}
} catch (NumberFormatException e) {
} catch (NotFoundException e) {
} catch (PatternSyntaxException e) {
} catch (NullPointerException e) {
}
return value;
}Код: Выделить всё
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.sp), getResources().getDisplayMetrics())