屏幕适配之px转dip
1 import android.content.Context; 2 3 public class DensityUtils { 4 5 /** 6 * 把PX转化为dip 7 * @param context 8 * @param px 9 * @return 10 */ 11 public static int px2dip(Context context,float px){ 12 13 float density = context.getResources().getDisplayMetrics().density; 14 int dip = (int) (px * density); 15 16 return dip; 17 } 18 }
mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT,DensityUtils.px2dip(getApplicationContext(), 70));将70的像素转换为dip
(上面公式参考google官方文档)