android 像素处理

来源:互联网 发布:威廉古堡知乎 编辑:程序博客网 时间:2024/05/21 07:50

dp和px的相互转换


public int Dp2Px( float dp) { 

    final float scale = getActivity().getResources().getDisplayMetrics().density; 
    return (int) (dp * scale + 0.5f); 


public int Px2Dp( float px) { 
    final float scale = getActivity().getResources().getDisplayMetrics().density; 
    return (int) (px / scale + 0.5f); 
0 0