标签:gets ice tpi 屏幕宽度 sys stat window === new
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
/**
* Created by 怪胎 on 2018.6.6.
*/
public class GetHeightandWidth {
public static int getwidth(Context context){
WindowManager wm = (WindowManager) context.getSystemService(context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels; // 屏幕宽度(像素)
// int height = dm.heightPixels; // 屏幕高度(像素)
// float density = dm.density; // 屏幕密度(0.75 / 1.0 / 1.5)
// int densityDpi = dm.densityDpi; // 屏幕密度dpi(120 / 160 / 240)
// 屏幕宽度算法:屏幕宽度(像素)/屏幕密度
// int screenWidth = (int) (width / density); // 屏幕宽度(dp)
// int screenHeight = (int) (height / density);// 屏幕高度(dp)
// Log.e("width=======>",width+"");
// Log.e("height=======>",height+"");
return width;
}
public static int getheight(Context context){
WindowManager wm = (WindowManager) context.getSystemService(context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
// int width = dm.widthPixels; // 屏幕宽度(像素)
int height = dm.heightPixels; // 屏幕高度(像素)
// float density = dm.density; // 屏幕密度(0.75 / 1.0 / 1.5)
// int densityDpi = dm.densityDpi; // 屏幕密度dpi(120 / 160 / 240)
// 屏幕宽度算法:屏幕宽度(像素)/屏幕密度
// int screenWidth = (int) (width / density); // 屏幕宽度(dp)
// int screenHeight = (int) (height / density);// 屏幕高度(dp)
// Log.e("width=======>",width+"");
// Log.e("height=======>",height+"");
return height;
}
}
标签:gets ice tpi 屏幕宽度 sys stat window === new
原文地址:https://www.cnblogs.com/ysxy/p/9143191.html