Giter Club home page Giter Club logo

Comments (6)

liaohuyu avatar liaohuyu commented on August 17, 2024

追加一个问题,为什么副单位都是修改的DisplayMetrics.xdpi,而不是ydpi,是因为TypedValue计算的时候只用到xdpi么?

from androidautosize.

JessYanCoding avatar JessYanCoding commented on August 17, 2024

可以的,dpsp、副单位同时支持,这是我在设计 API 时就已经考虑了的,demo-subunits 不可以,是因为设置了 AutoSizeConfig.getInstance().getUnitsManager().setSupportDP(false); ,把这行代码去掉,只保留 AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(Subunits.MM); 即可让 dp 和副单位同时被支持,自己在 Demo 上实验

from androidautosize.

JessYanCoding avatar JessYanCoding commented on August 17, 2024
public static float applyDimension(int unit, float value,
                                       DisplayMetrics metrics)
    {
        switch (unit) {
        case COMPLEX_UNIT_PX:
            return value;
        case COMPLEX_UNIT_DIP:
            return value * metrics.density;
        case COMPLEX_UNIT_SP:
            return value * metrics.scaledDensity;
        case COMPLEX_UNIT_PT:
            return value * metrics.xdpi * (1.0f/72);
        case COMPLEX_UNIT_IN:
            return value * metrics.xdpi;
        case COMPLEX_UNIT_MM:
            return value * metrics.xdpi * (1.0f/25.4f);
        }
        return 0;
    }

系统只用到了 xdpi,那如果我改 ydpi 就毫无意义了

from androidautosize.

liaohuyu avatar liaohuyu commented on August 17, 2024

我试了下 同一个页面不能一起支持哦。 if (isBaseOnWidth) {
targetDensity = AutoSizeConfig.getInstance().getScreenWidth() * 1.0f / sizeInDp;
} else {
targetDensity = AutoSizeConfig.getInstance().getScreenHeight() * 1.0f / sizeInDp;
}
targetScaledDensity = targetDensity * (AutoSizeConfig.getInstance().
getInitScaledDensity() * 1.0f / AutoSizeConfig.getInstance().getInitDensity());
targetDensityDpi = (int) (targetDensity * 160);

        if (isBaseOnWidth) {
            targetXdpi = AutoSizeConfig.getInstance().getScreenWidth() * 1.0f / sizeInDp;
        } else {
            targetXdpi = AutoSizeConfig.getInstance().getScreenHeight() * 1.0f / sizeInDp;
        }

        mCache.put(key, new DisplayMetricsInfo(targetDensity, targetDensityDpi, targetScaledDensity, targetXdpi));,sizeInDp是固定了的,只能支持一个。。。。        可以请教下,ydpi系统什么用到了么?

from androidautosize.

JessYanCoding avatar JessYanCoding commented on August 17, 2024

可以,不知道测试了多少次了,你复制的代码根本不是支持副单位和 dp 的核心代码,如果你 manifest 写的是像素值,布局中有副单位和dp,那布局中的高宽值,全部用设计图中的像素,不要在将像素除以 density,除以 density 当然不行

直接在 demo-subunits 测试,把 AutoSizeConfig.getInstance().getUnitsManager().setSupportDP(false); 删掉,将布局里面的部分 mm 直接换成 dp,值不要改,得到显示效果和全部使用 mm 布局是一样的,除非我们两个用的不是一个东西,不然不可能不可以

from androidautosize.

liaohuyu avatar liaohuyu commented on August 17, 2024

这个明白了,我以为dp还是要正常dp。感谢大佬百忙之中的细心解答。

from androidautosize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.