pixel与dp换算

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int w = 672, h = 370;
int dpw = (int) (w / dm.density + 0.5);
int dph = (int) (h / dm.density + 0.5);
Log.e(TAG, "density="+dm.density+"dpw="+dpw+"dph="+dph);


SurfaceView mSurfaceView = (SurfaceView)findViewById(R.id.surfaceView1);
		
//RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(672, 370);
LayoutParams pa = new LayoutParams(672, 370);//pixel
pa.topMargin = 200;
pa.bottomMargin = 200;
mSurfaceView.setLayoutParams(pa);

surfaceview设background是没有意义的,因为会被图像填充,所以只能在relativeLayout里设?目前来看是的。

谢谢lcy, jy童鞋大笑

你可能感兴趣的:(pixel与dp换算)