search

Home  >  Q&A  >  body text

android 适配问题

在布局的时候px明显更适合适配,不用考虑像素密度,只需要知道分辨率就可以,为什么官方还推荐dp呢

PHPzPHPz2772 days ago592

reply all(7)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 18:03:06

    I recommend using the same ratio to adapt to different screens.
    For example: 160px as the unit.
    Write the corresponding drawable.
    If it is 320px, then it is 0.5
    If it is 640px, then it is 0.25
    And so on. Directly writing PX can adapt to most screens. This is also based on the writing method in Hong Yang's blog on CSDN. But the more troublesome thing is that there are many drawables to maintain. Just adapt to mainstream screens. You can try it. Hope you adopt it!

    reply
    0
  • 迷茫

    迷茫2017-04-17 18:03:06

    I must recommend the official document I translated: http://blog.csdn.net/wzy_1988...

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 18:03:06

    For Android adaptation, it is best to use the percentage tool currently provided by Google. That is, the layout is written in the form of percentage. There is almost no need to adapt to the resolution of each size screen, because it is a percentage, which is a bit similar to the front end. It's a trend.

    reply
    0
  • PHPz

    PHPz2017-04-17 18:03:06

    I recommend an article to you http://www.jianshu.com/p/f188...

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 18:03:06

    This is a sub-question, comrade
    Even the resolutions of ios products are very different, let alone the tens of thousands of android machines
    If you write a 500px wide control, it will only be three points on a 2k screen One, but it already occupies more than two-thirds of the width on a 720*1280 machine, and the UI cannot be viewed

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 18:03:06

    dp=px*160/dpi
    dpi=160 on the device 160dp=160px=1inch
    dpi=320 on the device 160dp=320px=1inch

    Using dp ensures that at any resolution, the visual effect of 160dp is 1 inch in length

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 18:03:06

    Now I use Hongyang’s autolayout

    reply
    0
  • Cancelreply