mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Changed: Use float dp parameter instead of int for ViewUtils.dpToPx()
to not lose precision
This commit is contained in:
@@ -216,15 +216,18 @@ public class ViewUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/** Convert value in device independent pixels (dp) to pixels (px) units. */
|
||||
public static int dpToPx(Context context, int dp) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
|
||||
public static float dpToPx(Context context, float dp) {
|
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setLayoutMarginsInDp(@NonNull View view, int left, int top, int right, int bottom) {
|
||||
Context context = view.getContext();
|
||||
setLayoutMarginsInPixels(view, dpToPx(context, left), dpToPx(context, top), dpToPx(context, right), dpToPx(context, bottom));
|
||||
setLayoutMarginsInPixels(view, (int) dpToPx(context, left), (int) dpToPx(context, top),
|
||||
(int) dpToPx(context, right), (int) dpToPx(context, bottom));
|
||||
}
|
||||
|
||||
public static void setLayoutMarginsInPixels(@NonNull View view, int left, int top, int right, int bottom) {
|
||||
|
Reference in New Issue
Block a user