简体   繁体   中英

Supporting different screens for android

This is my first time working with multiple screens. I want to build my application for multiple screens ie from sw320dp to sw720dp . I have created the following layout folders.

res/layout-sw320dp
res/layout-sw360dp
res/layout-sw480dp
res/layout-sw600dp
res/layout-sw720dp

I have copied all the xml files inside these folders. Is there anything else I need to add to make sure all the layouts support multiple screens. I have gone through the android documentation but I am not clear with the manifest.xml part. If anyone implemented multiple screen support in their application, so please do provide a description and implementation of the same.

Step 1 -You have to create different values folder for Different values for different screens. Go to Your Project / app / src / main / res. Right click on res and create different values folder in it.

Step - 2. Create folders named values-large values-small values-sw320dp values-sw320dp-hdpi values-sw320dp-xhdpi values-sw320dp-xxhdpi values-sw480dp values-sw600dp values-sw720dp Step - 3. Create dimensions.xml file in values folders. Different values for different screen size.

values-ldpi                     2.7" 240*320 ldpi
values-ldpi                     3.3" 240*400 ldpi
values-ldpi                     3.4" 240*432 ldpi

values-mdpi                     3.2" 320*480 mdpi

values-hdpi                     4.0" 480*800 hdpi
values-hdpi                     3.7" 480*854 hdpi

values-xhdpi                    4.7" 1280*720 xhdpi
values-xhdpi                    4.65" 720*1280 xhdpi

values-sw480dp                  5.1" 480*800 mdpi
values-sw480dp                  5.4" 480*854 mdpi

values-sw600dp                  7.0" tablet 1024*600 mdpi

values-sw720dp                  10.1" tablet 1280*800 mdpi

when you attach dimension.xml file with your layout than you will get direct effect with your screen size. This will help you to set dimensions for all type of screens.

There is a difference between supporting multiple screen sizes and creating different layout.xml files for each screen size.

In all the apps I've ever worked on, there were really only three different kinds of screens we cared about: small phones (years-old devices that our users weren't upgrading), "regular" phones (eg modern-day Samsung or LG phones etc), and tablets. Even considering those three kinds of screens, we often didn't need to create more than a single layout.xml file for a single screen.

If you have just one layout.xml file, it will display itself on any screen size. To "support" multiple screen sizes, you just need to make sure that your content looks good on short phones and tall phones, on wide phones and narrow phones, on phones and tablets, etc. This generally comes down to using dimensions like match_parent , or layout_weight to fill available space, etc.

It is only when you actually need to change what elements are on screen (as opposed to how big elements are) that you need to create extra layout.xml files. For instance, perhaps you know that a certain set of text + images just won't fit on smaller phones. Then you can create one res/layout/layout.xml that has only the text, and another res/layout-sw360dp/layout.xml that has the text + the image. Or maybe you have some content that you want to display side-by-side on a tablet, but you only want part of it on phones. Then you can make one res/layout/layout.xml with the normal content and one res/layout-sw600dp/layout.xml with the tablet-only content.

Regardless, when you decide that you do want to make multiple versions of a layout for different screen sizes, the only thing you have to do is create copies of your layout.xml in different layout-swXXXdp folders. Don't bother with layout-large unless your app supports really old API levels; the swXXXdp method is much more accurate and solves the same problem (but was only added in API 13).

Hey you dont need to do anything in manifest. You have done the part with layouts. Next you can do is to add support in drawable folder ie different density images for different sizes.

And if different screens require different values(dimentions etc) you need to create multiple file in values.

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