|
|
@@ -426,4 +426,76 @@ public class ViewTool {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public static View inflateFragmentPixelsById(Context context, int layoutId, ViewGroup container,
|
|
|
+ int width, int height) {
|
|
|
+ View views = LayoutInflater.from(context).inflate(layoutId, container);
|
|
|
+ if (views == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ DisplayMetrics dm2 = new DisplayMetrics();
|
|
|
+ ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
|
|
|
+ .getDefaultDisplay().getMetrics(dm2);
|
|
|
+ if (heightPixels <= 0) {
|
|
|
+ heightPixels = dm2.heightPixels;
|
|
|
+ widthPixels = dm2.widthPixels;
|
|
|
+ Class<?> c = null;
|
|
|
+ Object obj = null;
|
|
|
+ Field field = null;
|
|
|
+ int x = 0, sbar = 0;
|
|
|
+ try {
|
|
|
+ c = Class.forName("com.android.internal.R$dimen");
|
|
|
+ obj = c.newInstance();
|
|
|
+ field = c.getField("status_bar_height");
|
|
|
+ x = Integer.parseInt(field.get(obj).toString());
|
|
|
+ sbar = context.getResources().getDimensionPixelSize(x);
|
|
|
+ } catch (Exception e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ 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
|
|
|
+
|
|
|
+ int resourceId = resources.getIdentifier("navigation_bar_height",
|
|
|
+ "dimen", "android");
|
|
|
+ if (resourceId > 0) {
|
|
|
+
|
|
|
+ if (isScreenChange(context)) {
|
|
|
+ widthPixelsN += resources.getDimensionPixelSize(resourceId);
|
|
|
+ } else {
|
|
|
+ heightPixelsN += resources
|
|
|
+ .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);
|
|
|
+ }
|
|
|
+ if (lp.width > 0) {
|
|
|
+ lp.width = (int) (((float) lp.width) / width * widthPixels);
|
|
|
+ }
|
|
|
+ views.setLayoutParams(lp);
|
|
|
+ }
|
|
|
+ return views;
|
|
|
+ }
|
|
|
}
|