Skip to content
New issue

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

关于平板适配问题 #179

Closed
BrightVan opened this issue Jun 21, 2019 · 4 comments
Closed

关于平板适配问题 #179

BrightVan opened this issue Jun 21, 2019 · 4 comments

Comments

@BrightVan
Copy link

BrightVan commented Jun 21, 2019

1、如果用了这个框架,什么都不做的话,在平板上会放大很多
2、有些应用也不必专门为平板做一套UI,取消autoSize适配,默认的效果也不错。
3、实现onAdaptListener,在onAdaptBefore是在适配之前调用,这里取消适配应该是全局有效。

@Override
    public void onAdaptBefore(Object target, Activity activity) {
        if (AppUtils.isTablet(activity.getApplicationContext())) {
            LogUtils.d(TAG,"stopAutoSize");
            AutoSizeConfig.getInstance().stop(activity);
            return;
        }
        .........
  }

判断是否是平板的代码,感觉用屏幕比例判断要好一些,现在手机都出到7.x寸了

 public static boolean isTablet(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        if (wm == null) {
            return true;
        }
        Display display = wm.getDefaultDisplay();
        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);
        //屏幕比例
        double screenProportion = dm.heightPixels * 1.0 / dm.widthPixels;
        return screenProportion < 1.7;
    }

然而,AutoSizeConfig.getInstance().stop(activity)没有任何效果
放到启动页activity 里调用,按理说后面的界面都会取消适配的,然而还是无效。

@JessYanCoding
Copy link
Owner

JessYanCoding commented Jun 28, 2019

  1. 一套给手机设计的设计图,放在平板上,布局放大很多,是很正常的事情,因为这就是百分比适配库的特性,大家用平板就是想在平板上显示更多的内容,这没错,但百分比库做不到,不管你是小到手机还是大到TV,都是按百分比缩放,如果想在大屏幕上显示更多的内容,就不使用百分比库,直接使用原生的 dp 就可以做到,所以你停止这个框架就行。

  2. 停止这个框架,个人建议放在第一个 Activity 的 onCreate 中,因为 onAdaptListener 在运行状态下会多次调用,你在 App 启动前就可以知道这个设备是否是平板,不可能 App 运行时这个设备突然变成手机吧,所以在 App 刚启动时直接停止框架就可以了。

  3. stop(activity) 做的操作是,停止后续的屏幕适配,并且把 density 修改为初始的值,按理说不会出现问题,也没收到过类似的 issues,不过你如果出现问题的话,可以断点看下这个方法执行后,density 是否已经被修改为初始的值

@BrightVan
Copy link
Author

在第一个activity也不行。还是,直接clone,把contentprovider干掉,自己控制init。

@hanwentong
Copy link

在第一个activity也不行。还是,直接clone,把contentprovider干掉,自己控制init。

您好,我现在也是遇到这个问题,AutoSizeConfig.getInstance().stop(activity)没有任何效果,请问最后你是怎么解决的?

@JessYanCoding
Copy link
Owner

@hanwentong #249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants