public class Dimensions {
/**
* The FIRST_DIMENTION_NUMBER.
*/
public static final int FIRST_DIMENTION_NUMBER = 160;
/**
* The SECOND_DIMENTION_NUMBER.
*/
public static final int SECOND_DIMENTION_NUMBER = 213;
/**
* displayMetrics.
*/
private static DisplayMetrics displayMetrics;
/**
* Convert PX to DP.
* @param d
* number of PX.
* @param context
* application context.
* @return number of DP
*/
public static int convertDptoPx(final double d, final Context context) {
if (displayMetrics == null) {
displayMetrics = context.getResources().getDisplayMetrics();
}
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) ((d * FIRST_DIMENTION_NUMBER) / SECOND_DIMENTION_NUMBER), displayMetrics);
}
Home
»
android
»
Android Development
»
android tutorial
»
convert dp to px
»
convert px to dp
» Android Convert Dimensions Class
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment