|
|
@@ -81,7 +81,7 @@ public class ViewTool {
|
|
|
fllp.topMargin = (int) (((float) fllp.topMargin) / height * heightPixels);
|
|
|
fllp.bottomMargin = (int) (((float) fllp.bottomMargin)
|
|
|
/ height * heightPixels);
|
|
|
- } else if (views instanceof ConstraintLayout) {
|
|
|
+ } else if (views instanceof ConstraintLayout) {
|
|
|
ConstraintLayout.LayoutParams fllp = (ConstraintLayout.LayoutParams) lp;
|
|
|
fllp.leftMargin = (int) (((float) fllp.leftMargin) / width * widthPixels);
|
|
|
fllp.rightMargin = (int) (((float) fllp.rightMargin)
|
|
|
@@ -117,10 +117,8 @@ public class ViewTool {
|
|
|
} else if (view instanceof ViewGroup) {
|
|
|
initPixels(view, width, height);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static View inflateLayoutPixels(Context context, View views, int width, int height) {
|
|
|
@@ -128,8 +126,7 @@ public class ViewTool {
|
|
|
return null;
|
|
|
}
|
|
|
DisplayMetrics dm2 = new DisplayMetrics();
|
|
|
- ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
|
|
|
- .getDefaultDisplay().getMetrics(dm2);
|
|
|
+ ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm2);
|
|
|
if (heightPixels <= 0) {
|
|
|
heightPixels = dm2.heightPixels;
|
|
|
widthPixels = dm2.widthPixels;
|
|
|
@@ -148,20 +145,17 @@ public class ViewTool {
|
|
|
}
|
|
|
heightPixels = heightPixels - sbar;
|
|
|
}
|
|
|
-
|
|
|
Resources resources = context.getResources();
|
|
|
-
|
|
|
float heightPixelsN, widthPixelsN;
|
|
|
heightPixelsN = heightPixels;
|
|
|
widthPixelsN = widthPixels;
|
|
|
int rid = resources.getIdentifier("config_showNavigationBar", "bool",
|
|
|
"android");
|
|
|
if (resources.getBoolean(rid)) {
|
|
|
- // ��ȡ�������Ƿ���ʾtrue or false
|
|
|
+ // 获取导航栏是否显示true or false
|
|
|
int resourceId = resources.getIdentifier("navigation_bar_height",
|
|
|
"dimen", "android");
|
|
|
if (resourceId > 0) {
|
|
|
-
|
|
|
if (isScreenChange(context)) {
|
|
|
widthPixelsN += resources.getDimensionPixelSize(resourceId);
|
|
|
} else {
|
|
|
@@ -169,7 +163,6 @@ public class ViewTool {
|
|
|
.getDimensionPixelSize(resourceId);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
|
|
|
width = (int) ((9.0 / 16.0) * height);
|
|
|
@@ -192,10 +185,9 @@ public class ViewTool {
|
|
|
return views;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public static View inflateLayoutPixelsById(Context context, int layoutId,
|
|
|
- int width, int height) {
|
|
|
- View views = LayoutInflater.from(context).inflate(layoutId, null);
|
|
|
+ int width, int height) {
|
|
|
+ View views = LayoutInflater.from(context).inflate(layoutId, null);
|
|
|
if (views == null) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -222,18 +214,16 @@ public class ViewTool {
|
|
|
}
|
|
|
|
|
|
Resources resources = context.getResources();
|
|
|
-
|
|
|
float heightPixelsN, widthPixelsN;
|
|
|
heightPixelsN = heightPixels;
|
|
|
widthPixelsN = widthPixels;
|
|
|
int rid = resources.getIdentifier("config_showNavigationBar", "bool",
|
|
|
"android");
|
|
|
if (resources.getBoolean(rid)) {
|
|
|
- // ��ȡ�������Ƿ���ʾtrue or false
|
|
|
+ // 获取导航栏是否显示true or false
|
|
|
int resourceId = resources.getIdentifier("navigation_bar_height",
|
|
|
"dimen", "android");
|
|
|
if (resourceId > 0) {
|
|
|
-
|
|
|
if (isScreenChange(context)) {
|
|
|
widthPixelsN += resources.getDimensionPixelSize(resourceId);
|
|
|
} else {
|
|
|
@@ -241,7 +231,6 @@ public class ViewTool {
|
|
|
.getDimensionPixelSize(resourceId);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
|
|
|
width = (int) ((9.0 / 16.0) * height);
|
|
|
@@ -252,7 +241,6 @@ public class ViewTool {
|
|
|
initPixels(views, width, height);
|
|
|
ViewGroup.LayoutParams lp = views.getLayoutParams();
|
|
|
if (lp != null) {
|
|
|
-
|
|
|
if (lp.height > 0) {
|
|
|
lp.height = (int) (((float) lp.height) / height * heightPixels);
|
|
|
}
|
|
|
@@ -293,19 +281,16 @@ public class ViewTool {
|
|
|
}
|
|
|
|
|
|
Resources resources = context.getResources();
|
|
|
-
|
|
|
float heightPixelsN, widthPixelsN;
|
|
|
heightPixelsN = heightPixels;
|
|
|
widthPixelsN = widthPixels;
|
|
|
int rid = resources.getIdentifier("config_showNavigationBar", "bool",
|
|
|
"android");
|
|
|
if (resources.getBoolean(rid)) {
|
|
|
- // ��ȡ�������Ƿ���ʾtrue or false
|
|
|
-
|
|
|
+ // 获取导航栏是否显示true or false
|
|
|
int resourceId = resources.getIdentifier("navigation_bar_height",
|
|
|
"dimen", "android");
|
|
|
if (resourceId > 0) {
|
|
|
-
|
|
|
if (isScreenChange(context)) {
|
|
|
widthPixelsN += resources.getDimensionPixelSize(resourceId);
|
|
|
} else {
|
|
|
@@ -313,19 +298,16 @@ public class ViewTool {
|
|
|
.getDimensionPixelSize(resourceId);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
|
|
|
width = (int) ((9.0 / 16.0) * height);
|
|
|
-
|
|
|
} else if (widthPixelsN / heightPixelsN == 10.0 / 16.0) {
|
|
|
width = (int) ((10.0 / 16.0) * height);
|
|
|
}
|
|
|
initPixels(views, width, height);
|
|
|
ViewGroup.LayoutParams lp = views.getLayoutParams();
|
|
|
if (lp != null) {
|
|
|
-
|
|
|
if (lp.height > 0) {
|
|
|
lp.height = (int) (((float) lp.height) / height * heightPixels);
|
|
|
}
|
|
|
@@ -362,21 +344,17 @@ public class ViewTool {
|
|
|
}
|
|
|
heightPixels = heightPixels - sbar;
|
|
|
}
|
|
|
-
|
|
|
Resources resources = context.getResources();
|
|
|
-
|
|
|
float heightPixelsN, widthPixelsN;
|
|
|
heightPixelsN = heightPixels;
|
|
|
widthPixelsN = widthPixels;
|
|
|
int rid = resources.getIdentifier("config_showNavigationBar", "bool",
|
|
|
"android");
|
|
|
if (resources.getBoolean(rid)) {
|
|
|
- // ��ȡ�������Ƿ���ʾtrue or false
|
|
|
-
|
|
|
+ // 获取导航栏是否显示true or false
|
|
|
int resourceId = resources.getIdentifier("navigation_bar_height",
|
|
|
"dimen", "android");
|
|
|
if (resourceId > 0) {
|
|
|
-
|
|
|
if (isScreenChange(context)) {
|
|
|
widthPixelsN += resources.getDimensionPixelSize(resourceId);
|
|
|
} else {
|
|
|
@@ -384,19 +362,16 @@ public class ViewTool {
|
|
|
.getDimensionPixelSize(resourceId);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
|
|
|
width = (int) ((9.0 / 16.0) * height);
|
|
|
-
|
|
|
} else if (widthPixelsN / heightPixelsN == 10.0 / 16.0) {
|
|
|
width = (int) ((10.0 / 16.0) * height);
|
|
|
}
|
|
|
initPixels(views, width, height);
|
|
|
ViewGroup.LayoutParams lp = views.getLayoutParams();
|
|
|
if (lp != null) {
|
|
|
-
|
|
|
if (lp.height > 0) {
|
|
|
lp.height = (int) (((float) lp.height) / height * heightPixels);
|
|
|
}
|
|
|
@@ -409,18 +384,14 @@ public class ViewTool {
|
|
|
}
|
|
|
|
|
|
public static boolean isScreenChange(Context context) {
|
|
|
-
|
|
|
Configuration mConfiguration = context.getResources()
|
|
|
- .getConfiguration(); // ��ȡ���õ�������Ϣ
|
|
|
- int ori = mConfiguration.orientation; // ��ȡ��Ļ����
|
|
|
-
|
|
|
+ .getConfiguration(); // 获取设置的配置信息
|
|
|
+ int ori = mConfiguration.orientation; // 获取屏幕方向
|
|
|
if (ori == mConfiguration.ORIENTATION_LANDSCAPE) {
|
|
|
-
|
|
|
- // ����
|
|
|
+ // 横屏
|
|
|
return true;
|
|
|
} else if (ori == mConfiguration.ORIENTATION_PORTRAIT) {
|
|
|
-
|
|
|
- // ����
|
|
|
+ // 竖屏
|
|
|
return false;
|
|
|
}
|
|
|
return false;
|
|
|
@@ -453,21 +424,17 @@ public class ViewTool {
|
|
|
}
|
|
|
heightPixels = heightPixels - sbar;
|
|
|
}
|
|
|
-
|
|
|
Resources resources = context.getResources();
|
|
|
-
|
|
|
float heightPixelsN, widthPixelsN;
|
|
|
heightPixelsN = heightPixels;
|
|
|
widthPixelsN = widthPixels;
|
|
|
int rid = resources.getIdentifier("config_showNavigationBar", "bool",
|
|
|
"android");
|
|
|
if (resources.getBoolean(rid)) {
|
|
|
- // ��ȡ�������Ƿ���ʾtrue or false
|
|
|
-
|
|
|
+ // 获取导航栏是否显示true or false
|
|
|
int resourceId = resources.getIdentifier("navigation_bar_height",
|
|
|
"dimen", "android");
|
|
|
if (resourceId > 0) {
|
|
|
-
|
|
|
if (isScreenChange(context)) {
|
|
|
widthPixelsN += resources.getDimensionPixelSize(resourceId);
|
|
|
} else {
|
|
|
@@ -475,19 +442,16 @@ public class ViewTool {
|
|
|
.getDimensionPixelSize(resourceId);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
|
|
|
width = (int) ((9.0 / 16.0) * height);
|
|
|
-
|
|
|
} else if (widthPixelsN / heightPixelsN == 10.0 / 16.0) {
|
|
|
width = (int) ((10.0 / 16.0) * height);
|
|
|
}
|
|
|
initPixels(views, width, height);
|
|
|
ViewGroup.LayoutParams lp = views.getLayoutParams();
|
|
|
if (lp != null) {
|
|
|
-
|
|
|
if (lp.height > 0) {
|
|
|
lp.height = (int) (((float) lp.height) / height * heightPixels);
|
|
|
}
|