我读到有两种引用像素 - w3c 引用像素和倾 Angular 像素。我不明白如何使用倾斜像素。我是否必须写,例如,“width:100dip”或类似的东西。我如何在我的 html+css+javascript 代码中指定这个倾斜像素?
最佳答案
在 XML 中:
android:layout_width="100dp"
在 Java 中:
int width = dpToPx(100);
public static int dpToPx(int dpWidth) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
float screenDpWidth = displayMetrics.widthPixels / displayMetrics.density;
int screenPxWidth = Math.round((screenDpWidth) * displayMetrics.density);
int dpPxWidth = Math.round(screenPxWidth / screenDPWidth);
return dpPxWidth * dpWidth;
}
关于android - 如何在代码中指定倾 Angular 像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39154382/