public final class

Density

extends Object
java.lang.Object
   ↳ com.neomades.graphics.Density

Class Overview

Utility class to convert DP to Pixels

These methods use the density given by Android, which is :
  • 0.75 on a ldpi screen
  • 1 on an mdpi screen
  • 1.5 on an hdpi screen
  • 2 on an xhdpi screen
So with theses methods, we take into account the logical density given by Android, but not the real density of the screen.

Summary

Public Methods
static int toDP(int pixels)
This methods converts pixels into dp units, according to the logical range's density.
static int toPixels(int dp)
This methods converts dp into pixel units, according to the logical range's density.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static int toDP (int pixels)

This methods converts pixels into dp units, according to the logical range's density.

Parameters
pixels the pixels to convert
Returns
  • the dp units corresponding to the given pixels value

public static int toPixels (int dp)

This methods converts dp into pixel units, according to the logical range's density.

Parameters
dp the dp to convert
Returns
  • the pixel units corresponding to the given dp value