密度:density值表示每英寸有多少个显示点。
分辨率:屏幕上拥有的像素的总数。注意,虽然大部分情况下分辨率都被表示为“宽度×长度”,但分辨率并不意味着屏幕长宽比
屏幕尺寸:屏幕的物理尺寸,以屏幕的对角线长度作为依据(比如2.8寸,3.5寸)
获取屏幕宽高
DisplayMetrics metrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int w=metrics.widthPixels; // 屏幕宽(像素,如:480px)
int h=metrics.heightPixels; // 屏幕高(像素,如:800px)
float d=metrics.density; //屏幕密度(像素比例:0.75/1.0/1.5/2.0)
int dp=metrics.densityDpi; //屏幕密度(每寸像素:120/160/240/320)
获取View宽高
/**
* 获取view宽高
* 0:高
* 1:宽
* */
public int[] getWithAndHight(View view) {
int[] location = new int[2];
int width = View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED);
int height = View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED);
view.measure(width, height);
location[0] = view.getMeasuredHeight();
location[1] = view.getMeasuredWidth();
return location;
}