小编Pra*_*mar的帖子

从dp转换为像素错误

由于一些奇怪的原因,我无法从下面的函数得到正确的输出,我知道我做了一些愚蠢的错误,但不确定,

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);

输出是一个巨大的数字,这是不期望的,任何帮助非常赞赏.

android android-layout

0
推荐指数
1
解决办法
2172
查看次数

标签 统计

android ×1

android-layout ×1