April 29, 2010

[SOLVED] Android: Convert dip to px.

It uses pixels, but I'm sure you're wondering how to use dips instead. The answer is inTypedValue.applyDimension()Here's an example of how to convert dips to px in code:

// Converts 14 dip into its equivalent px
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics());

Source: Does setWidthint pixels use dip or px? - Stack Overflow.

No comments:

Post a Comment