We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
非常感谢楼主的分享:
问题: 横屏时 打开一个竖屏使用的弹窗 UI元素过大的优化。
解决:AutoSize.java
private static DisplayMetricsInfo mCacheMetricsInfo; public static void autoConvertDensity(Activity activity, float sizeInDp, boolean isBaseOnWidth) { Preconditions.checkNotNull(activity, "activity == null"); Preconditions.checkMainThread(); float subunitsDesignSize = isBaseOnWidth ? AutoSizeConfig.getInstance().getUnitsManager().getDesignWidth() : AutoSizeConfig.getInstance().getUnitsManager().getDesignHeight(); subunitsDesignSize = subunitsDesignSize > 0 ? subunitsDesignSize : sizeInDp; //第一次计算密度之后,以后一直使用该值,保证所有页面使用相同大小 float targetDensity = 0; int targetDensityDpi = 0; float targetScaledDensity = 0; float targetXdpi = 0; int targetScreenWidthDp; int targetScreenHeightDp; if (mCacheMetricsInfo == null) { if (isBaseOnWidth) { targetDensity = AutoSizeConfig.getInstance().getScreenWidth() * 1.0f / sizeInDp; } else { targetDensity = AutoSizeConfig.getInstance().getScreenHeight() * 1.0f / sizeInDp; } if (AutoSizeConfig.getInstance().getPrivateFontScale() > 0) { targetScaledDensity = targetDensity * AutoSizeConfig.getInstance().getPrivateFontScale(); } else { float systemFontScale = AutoSizeConfig.getInstance().isExcludeFontScale() ? 1 : AutoSizeConfig.getInstance(). getInitScaledDensity() * 1.0f / AutoSizeConfig.getInstance().getInitDensity(); targetScaledDensity = targetDensity * systemFontScale; } targetDensityDpi = (int) (targetDensity * 160); targetScreenWidthDp = (int) (AutoSizeConfig.getInstance().getScreenWidth() / targetDensity); targetScreenHeightDp = (int) (AutoSizeConfig.getInstance().getScreenHeight() / targetDensity); if (isBaseOnWidth) { targetXdpi = AutoSizeConfig.getInstance().getScreenWidth() * 1.0f / subunitsDesignSize; } else { targetXdpi = AutoSizeConfig.getInstance().getScreenHeight() * 1.0f / subunitsDesignSize; } mCacheMetricsInfo = new DisplayMetricsInfo(targetDensity, targetDensityDpi, targetScaledDensity, targetXdpi, targetScreenWidthDp, targetScreenHeightDp); } else { targetDensity = mCacheMetricsInfo.getDensity(); targetDensityDpi = mCacheMetricsInfo.getDensityDpi(); targetScaledDensity = mCacheMetricsInfo.getScaledDensity(); targetXdpi = mCacheMetricsInfo.getXdpi(); targetScreenWidthDp = mCacheMetricsInfo.getScreenWidthDp(); targetScreenHeightDp = mCacheMetricsInfo.getScreenHeightDp(); } setDensity(activity, targetDensity, targetDensityDpi, targetScaledDensity, targetXdpi); setScreenSizeDp(activity, targetScreenWidthDp, targetScreenHeightDp); AutoSizeLog.d(String.format(Locale.ENGLISH, "The %s has been adapted! \n%s Info: isBaseOnWidth = %s, %s = %f, %s = %f, targetDensity = %f, targetScaledDensity = %f, targetDensityDpi = %d, targetXdpi = %f, targetScreenWidthDp = %d, targetScreenHeightDp = %d" , activity.getClass().getName(), activity.getClass().getSimpleName(), isBaseOnWidth, isBaseOnWidth ? "designWidthInDp" : "designHeightInDp", sizeInDp, isBaseOnWidth ? "designWidthInSubunits" : "designHeightInSubunits", subunitsDesignSize , targetDensity, targetScaledDensity, targetDensityDpi, targetXdpi, targetScreenWidthDp, targetScreenHeightDp)); } /** * 取消适配 * * @param activity {@link Activity} */ public static void cancelAdapt(Activity activity) { Preconditions.checkMainThread(); float initXdpi = AutoSizeConfig.getInstance().getInitXdpi(); switch (AutoSizeConfig.getInstance().getUnitsManager().getSupportSubunits()) { case PT: initXdpi = initXdpi / 72f; break; case MM: initXdpi = initXdpi / 25.4f; break; default: } setDensity(activity, AutoSizeConfig.getInstance().getInitDensity() , AutoSizeConfig.getInstance().getInitDensityDpi() , AutoSizeConfig.getInstance().getInitScaledDensity() , initXdpi); setScreenSizeDp(activity , AutoSizeConfig.getInstance().getInitScreenWidthDp() , AutoSizeConfig.getInstance().getInitScreenHeightDp()); } /** * 给 {@link Configuration} 赋值 * * @param activity {@link Activity} * @param screenWidthDp {@link Configuration#screenWidthDp} * @param screenHeightDp {@link Configuration#screenHeightDp} */ private static void setScreenSizeDp(Activity activity, int screenWidthDp, int screenHeightDp) { if (AutoSizeConfig.getInstance().getUnitsManager().isSupportDP() && AutoSizeConfig.getInstance().getUnitsManager().isSupportScreenSizeDP()) { Configuration activityConfiguration = activity.getResources().getConfiguration(); setScreenSizeDp(activityConfiguration, screenWidthDp, screenHeightDp); Configuration appConfiguration = AutoSizeConfig.getInstance().getApplication().getResources().getConfiguration(); setScreenSizeDp(appConfiguration, screenWidthDp, screenHeightDp); } } /** * Configuration赋值 * * @param configuration {@link Configuration} * @param screenWidthDp {@link Configuration#screenWidthDp} * @param screenHeightDp {@link Configuration#screenHeightDp} */ private static void setScreenSizeDp(Configuration configuration, int screenWidthDp, int screenHeightDp) { configuration.screenWidthDp = screenWidthDp; configuration.screenHeightDp = screenHeightDp; }
是否存在其他方式解决该问题?
The text was updated successfully, but these errors were encountered:
+1,同遇到这个问题
Sorry, something went wrong.
#288 #134
你好我的是项目中横屏页面,然后锁屏,解锁,页面会错乱 各种适配失效大小错乱
請問有解嗎
No branches or pull requests
非常感谢楼主的分享:
问题: 横屏时 打开一个竖屏使用的弹窗 UI元素过大的优化。
解决:AutoSize.java
是否存在其他方式解决该问题?
The text was updated successfully, but these errors were encountered: