Implementing multiple layout for multiple screen support is not working

后端 未结 2 423
孤独总比滥情好
孤独总比滥情好 2021-01-29 11:16

I have read many things about supporting multiple devices. Right now I have implemented it in my application, I have made following folders as shown below :

  1. layout
2条回答
  •  孤城傲影
    2021-01-29 11:49

    According to the note written in this documentation Supporting Multiple Screens, the old groups was deprecated (small, normal, large, and xlarge), which is why we have to migrate to the new technique defined in Android 3.2.

    Note: Beginning with Android 3.2 (API level 13), these size groups are deprecated in favor of a new technique for managing screen sizes based on the available screen width. If you're developing for Android 3.2 and greater, see Declaring Tablet Layouts for Android 3.2 for more information.

    Old way classification :

    xlarge screens are at least 960dp x 720dp
    large screens are at least 640dp x 480dp
    normal screens are at least 470dp x 320dp
    small screens are at least 426dp x 320dp
    

    New way :New configuration qualifiers for screen size (introduced in Android 3.2).

    320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
    480dp: a tweener tablet like the Streak (480x800 mdpi).
    600dp: a 7” tablet (600x1024 mdpi).
    720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
    
    res/layout-sw320dp/main_activity.xml # For handsets (smaller than 600dp available width)
    res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
    res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
    

    Refer the Supporting Multiple Screens documentation for more support !!

    So here also there will be a weird problem we have that to controlling the different mobile devices (not tablets) i.e we have devices like 3.5' 5', 5.5' and so on.

    So to achieve the multiple mobile screen support (accurately) you can create different values folders in your app like below

    Then declare all your dimension values in the dimens.xml file as your need , and use the values from the dimension file (it means not hard coded values in your xml files.. every value should be come from dimens file like @dimen/ ) For example in you home screen you have a left padding of 5dp and text size of 24sp and some other dimension values also.

    So you need to create a dimens.xml file in your values folder like below.

    120dp
    15dp
    10dp
    37dp
    5dp
    

    then you can use the same in your xml file like below

    in the same way you can create different dimens.xml files in different values folders and then you can create the same dimension names & change your required sp & dp values.. so that while loading the xml file it will take the dimension values from required values folder

    This link may help you for more details

提交回复
热议问题