本文介绍了在高端设备上绘制画布问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式在画布上绘制 c> 从 dp / code>。
You can get px from dp depending on the screen density of the device and use that in LayoutParams.
public static float convertDpToPixel(float dp, Context context){ Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); // You can cache "((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)" to avoid re-calculation. return px; }
因此,您将创建 param 这样:
zoomBarParams = new LinearLayout.LayoutParams(convertDpToPixel(DP_VALUE, context), LayoutParams.FILL_PARENT);
其中 DP_VALUE 。
我希望这可能解决您的问题。
I hope this might solve your problem.
这篇关于在高端设备上绘制画布问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!