Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a dimension string and convert it to a dimension value

Tags:

I'm looking for a way to dynamically convert a String like "30dp" into an int that resembles the amount of pixels. This would mean that StaticClass.theMethodImSearchingFor("16px") would return 16.
My application will get these Strings dynamically and I need a way to store it as a pixel value to use later.
I've already looked at the Android Source code, mainly the classes Resources, TypedArray and TypedValue, but I couldn't find anything useful.

like image 982
ArnoldOverwater Avatar asked Dec 01 '11 15:12

ArnoldOverwater


1 Answers

If you need the android resource dimen as a int you can do this in your code:

context.getResources().getDimensionPixelSize(R.dimen.your_dimen_res);
like image 186
Cata Avatar answered Sep 17 '22 19:09

Cata