简体   繁体   中英

How to create a layout folder for a smaller screen size?

I am working on updating a legacy project and I need to create additional layout files for a smaller screen size. In the past, when creating multiple versions of a layout for various screen sizes, I have put the layouts for the smallest screen size in the base layout folder and created secondary layout folders with smallest width qualifiers to support larger screen sizes.

For example:

res/layout            //base layouts
res/layout-sw720dp    //layouts for screen with at least 720dp width

However, I have been unable to find a way to handle the reverse case where I already have the layouts for the larger screen size in the base layout folder and I want a new layout folder for a smaller screen size. I was hoping to find a "maximum width" qualifier but it doesn't seem to exist.

If I had to update every layout for the smaller screen size then I would simply move my larger screen layouts to a folder with a smallest width qualifier and add the smaller screen size layouts to the base layout folder, but I only need to update 10% of the layouts for the smaller screen size.

I have put the layouts for the smallest screen size in the base layout folder and created secondary layout folders with smallest width qualifiers to support larger screen sizes.

That is the correct approach, both for your original scenario and your new one. More specifically, your "secondary layout folders" would only contain layouts where you need to change something based on that larger screen size. Everything else would only be in res/layout/ .

I was hoping to find a "maximum width" qualifier but it doesn't seem to exist.

Correct.

If I had to update every layout for the smaller screen size then I would simply move my larger screen layouts to a folder with a smallest width qualifier but I only need to update 5 of the 50 or so layouts for the smaller screen size.

Sorry, but you do not really have a choice. res/layout/ needs to hold one copy of every layout, set up for the smallest screen size that you are going to support. You override for larger screen sizes for the specific layouts that need to change for those larger screen sizes.

There is no means of saying that res/layout/ is in the middle of the screen size range, and you want to override for smaller sizes as well as for larger sizes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM