Android layout folders for different screen sizes

不想你离开。 提交于 2019-12-12 13:13:12

问题


I have an app that I need to ensure different devices are pulling from different layout folders. I need a nexus 5 (1920 x 1080) to pull from a different folder than a Note 4 (2560 x 1440).

Currently, no matter what combination of folder names, they both pull from the same folder.

I have tried:

layout-xxhdpi & layout-xxxhdpi 

(they both pull from xxhdpi)

layout-sw320dp & layout-xxhdpi

(they both pull from layout-sw320dp

layout-large & layout-xlarge

(they both pull from layout-large)

What would be the proper layout folder convention for this situation?


回答1:


Actually you need to add the following folders:

  • layout-sw320dp (xhdpi devices)
  • layout-sw340dp (xxhdpi devices)
  • layout-sw380dp (xxxhdpi devices)

you must add folders only if you really need another whole layout in different devices. Other than that , use only default layout folder with proper layout structure and extract dimensions on different density folders.




回答2:


So this seems to be the only arrangement that worked for me...

layout (Nexus 4 & 5)

layout-sw440dp-port (Note 4, Nexus 6)

layout-sw720dp-port (Samsung 10" tablet)

(It I take off the "port" it doesn't work...) ;-)

Thanx for all the suggestions!




回答3:


According to Google device metrics, Note 4 and Nexus 5 both have xxhdpi density, but their widths and heights are different, so you should try playing with the smallestWidth qualifier. For example with this combination should work: layout-sw360dp & layout-sw480dp (You can read more about qualifiers here)




回答4:


This is the structure:

    res/layout
    res/layout-large
    res/layout-xlarge
    res/layout-sw600dp
    res/layout-sw720dp
    res/layout-sw800dp


来源:https://stackoverflow.com/questions/34437942/android-layout-folders-for-different-screen-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!