Skip to content

Instantly share code, notes, and snippets.

@sunwicked
Created May 12, 2014 09:23
Show Gist options
  • Save sunwicked/812cce49c38fb8c568d8 to your computer and use it in GitHub Desktop.
Save sunwicked/812cce49c38fb8c568d8 to your computer and use it in GitHub Desktop.
Converting dp units to pixel units
// The gesture threshold expressed in dp
private static final float GESTURE_THRESHOLD_DP = 16.0f;
// Get the screen's density scale
final float scale = getResources().getDisplayMetrics().density;
// Convert the dps to pixels, based on density scale
mGestureThreshold = (int) (GESTURE_THRESHOLD_DP * scale + 0.5f);
// Use mGestureThreshold as a distance in pixels...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment