Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics());
// Converts dp to px
public static float convertDpToPixel( float dp,Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * (metrics.densityDpi/160f);
return px;
}
// Converts px to dp
public static float convertPixelsToDp( float px,Context context){
// Converts px to dp
public static float convertPixelsToDp( float px,Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return dp;
}
}
댓글 없음:
댓글 쓰기