Skip to content

Instantly share code, notes, and snippets.

@TheFinestArtist
Created July 25, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheFinestArtist/bacfb106d43c67ea7a1d to your computer and use it in GitHub Desktop.
Save TheFinestArtist/bacfb106d43c67ea7a1d to your computer and use it in GitHub Desktop.
DipPixelHelper.java
import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;
/**
* DipPixelHelper
*
* @author The Finest Artist
*/
public class DipPixelHelper {
public static float getPixel(Context context, int dip) {
Resources r = context.getResources();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
}
public static float getPixel(Context context, float dip) {
Resources r = context.getResources();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment