由于一些奇怪的原因,我无法从下面的函数得到正确的输出,我知道我做了一些愚蠢的错误,但不确定,
public static int convertDpToPixel(int dp, Context context){
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dp,context.getResources().getDisplayMetrics());
return Math.round(px);
}
Run Code Online (Sandbox Code Playgroud)
而我正在调用函数 - gen_function.convertDpToPixel(R.dimen.button_left_right_margin,this);
输出是一个巨大的数字,这是不期望的,任何帮助非常赞赏.