How to get dip value in place of pixels, through Android programming

By default int values will be considered as pixels in programming. To use dip value instead of pixels we have to use “TypedValue.applyDimension()".

For Example:

Resources resources = getResources();
float dipValue = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 75, resources.getDisplayMetrics());
Log.d(“LobActivity”, “dipValue : “+dipValue );

If you run above code in different density emulators, you can identify the different values are being  generated for dipValue.

Advertisements

1 Comment

Filed under Uncategorized

One response to “How to get dip value in place of pixels, through Android programming

  1. joe

    I just get back 75 as the float value. this doesnt work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s