Android Scaling & Density Issues

后端 未结 2 578
梦谈多话
梦谈多话 2021-01-24 17:42

Update: Some research has turned up that the Asus Transformer TF700T (high end) should have a pixel density of about 224, so the values of 159 android is report

相关标签:
2条回答
  • 2021-01-24 17:52

    Looks like you do something like I did. I mean you think that AOS chooses resources using DisplayMetrics but thats not true. There is also a Configuration. So for instance I was thinking that my HTC is HDPI for AOS since its really hdpi/240 by DisplayMetrics. But by Configuration its NORMAL. pls look at stackoverflow.com/questions/15837469/… maybe u'r gonna find it useful.
    So maybe one of your tablets must use res/large-mdpi and the other res/large-hdpi.

    0 讨论(0)
  • 2021-01-24 18:10

    Note: I'm not accepting my own answered so that hopefully someone that knows what is going on with this will take a shot. I'm posting this answer b/c it did solve my problem, but still doesn't address some underlying questions and mysteries.


    Well, after doing some calculations of my own, it looks as though the high-end device has more accurate Xdpi/Ydpi values, and the lower end device is reporting higher than calculated values. Both have physical dimensions of

    length = 7.12"
    width = 10.35"
    

    so, we have for the high-end tablet

    Xdpi = 1920 / 10.35 = 185.5
    Ydpi = 1128 / 7.12 = 158.4
    

    and for the low-end one

    Xdpi = 1280 / 10.35 = 123.7
    Ydpi = 752 / 7.12 = 105.6
    

    Asus documentation states that

    dpi (high-end) = 224
    dpi (low-end) = 149
    

    I do realize that android "buckets" devices into 4 groups based on density: low, medium, high, very-high, and assigns the (abstract) dpi value (in /system/build.prop) with preset values based on these: 120, 160, 240, and 320 respectively.

    Despite these values, android did correctly report the Density (scaling factor) for each, which was

    Density (high-end) = 1.5
    Density (low-end) = 1
    

    So, as suggested by android (http://developer.android.com/guide/practices/screens_support.html) for supporting multiple screens, I made two Values folders for two versions of dimens.xml (where the size's were defined):

    Resources/Values-Hdpi/dimens.xml
    Resources/Values-Mdpi/dimens.xml
    

    and adjusted the values accordingly, where Values-Hdpi/dimens.xml had smaller values to compensate for the 1.5 scaling factor, and Values-Mdpi/dimens.xml had "normalized" values that get scaled by 1. Both tablets now correctly display the correct sizes. But, isn't that what the dp/dip metric is for, so that these separate value sets do not need to be explicitly defined ?

    0 讨论(0)
提交回复
热议问题