WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display d = windowManager.getDefaultDisplay(); mWidth = d.getWidth();mHeight = d.getHeight(); DisplayMetrics dm = getResources().getDisplayMetrics() mScreenDensity = dm.density;
float scaleWidth = mWidth / uiWidth; float scaleHeight = mHeight/ uiHeight;
public static int getWidthSize(int size) {
return (int) (size * scaleWidth);
}
public static int getHightSize(int size) {
return (int) (size * scaleHeight);
}
public static float getTextSize(int pxSize) {
return (pxSize * scaleHeight) / mScreenDensity;
}
public static void setViewSize(int width, int height, View v) {
int paramWidth = getWidthSize(width);
int paramHeight = getHightSize(height);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v
.getLayoutParams();
if (width != INVALID) {
params.width = paramWidth;
}
if (height != INVALID) {
params.height = paramHeight;
}
v.setLayoutParams(params);
}
public static void setViewPadding(int left, int top, int right, int bottom,
View v) {
left = getWidthSize(left);
top = getHightSize(top);
right = getWidthSize(right);
bottom = getWidthSize(bottom);
v.setPadding(left, top, right, bottom);
}
public static void setViewMargin(int left, int top, int right, int bottom,
View v) {
int paramLeft = getWidthSize(left);
int paramTop = getHightSize(top);
int paramRight = getWidthSize(right);
int paramBottom = getHightSize(bottom);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v
.getLayoutParams();
if (left != INVALID) {
params.leftMargin = paramLeft;
}
if (right != INVALID) {
params.rightMargin = paramRight;
}
if (top != INVALID) {
params.topMargin = paramTop;
}
if (bottom != INVALID) {
params.bottomMargin = paramBottom;
}
v.setLayoutParams(params);}
setViewSize(100, 100, mView);
setViewMargin(20, 0, 0, 20, mView);
setViewPadding(10, 10, 10, 10, mView);
mTextView.setTextSize(getTextSize(30));
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有