Search code examples
androidandroid-layouttabletscreen-resolutionscreen-size

How do I calculate values for dimens for sw600dp and sw720dp?


I have read lot of posts on how to handle multiple device screens for tablet only app. But I have got all mixed views about how to approach this implementation.

The app needs to only be built for tablets (above 5.0). So I went ahead with the approach of using values-sw600dp(7" inch tablet) and values-sw720dp(10" tablet) folders and keeping the layout folder as just one(as there is not much difference in portrait and landscape orientation, the UI pretty much is the same for both).

Can someone help me how would I calculate the dimens.xml values for sw600dp and sw720dp, as I do see that most of the sw600dp devices are mdpi. And what about the sw720dp ? OR Do I need to handle values-xhdpi separately?

I am not sure what values will go in these specific directories. Will I be putting all mdpi values in sw600dp and xhdpi in sw720dp ?

Any help appreciated.

Thanks.


Solution

  • Good question Sneha, So you can get as custom as you like, but I recommend staying as generic as possible to save yourself a maintenance nightmare. Do not separate your Dimens by L,M,H,XH,XXH,XXXH. Stick with just the sw600dp or sw630dp for your 7" tablets and the sw720dp or sw820dp for your 10 inch tablet.

    Typically you find what works best for your design and you keep it consistent.

    For example if you develop a phone app you have

    values/dimens.xml in this file you have various values

    <someHeight>10</>
    <someWidth>20</>
    

    please ignore my pseduo code haha. then in the sw630dp-values/dimens.xml I typically apply a 1.5x multiplier

    <someHeight>15</>
    <someWidth>30</>
    

    then of course open your preview pane and look on various devices to make sure you are happy with this scale decision.

    For your sw720dp-values/dimens.xml you may want to apply a 2x multiplier, but it is really about maximizing your screen real estate for a natural user experience that doesn't look too big or too small for the device or to the user. So you may have to tweak your multipler, and you certainly can individually adjust values, but typically if you get your multiplier just right, it can be universally applied to the whole sw values dir of that size.

    Using the M,H,XH, etc.. is more reserved for your assets like images that may be uniquely sized for that grouping of device but the width and height or placement of that image can stay handled by the dimens file of that respective size.

    If your studio is setup correctly the preview pane should choose to use the correct dimens file for the selected preview device. I have found in the past that it doesn't always work and I have to preview on standard real device, but it does work.

    Hope this helps and goodluck.