I need some suggestion with supporting multiple screen size,
this
values
values-hdpi
values-large
values-ldpi
values-mdpi
values-small
values-xhdpi
values-xlarge
or this
values-sw360dp
values-sw600dp-land
values-sw600dp-v21
values-sw720dp-land
values-sw720dp
values-v17
values-v21
values-2400dp
values-w720dp-land
values-w720dp
what values folders should i create in the res?i want to know all of it, if i may
Do i need to programmaticly declare or just put @dimens/something in the layout xml?
3.DO i need to make more layout folders to support multi screen size or just one layout folder and using @dimens is enough to handle multi screen size?
First and foremost, the following are depreciated from Android 3.2 (API 13) and up...
values
values-hdpi
values-large
values-ldpi
values-mdpi
values-small
values-xhdpi
values-xlarge
Basically, you only need to use these when you are developing for devices running anything lower than Android 3.2 (API 13).
Smallest Width
values-sw360dp
values-sw600dp
values-sw600dp-land
values-sw600dp-v21
values-sw720dp-land
values-sw720dp
The "sw" means Smallest Width. The OS will pick the one that fits the smallest available width that is available to your activity window. Therefore, if you have a device that is 700dp wide, it will use the resources from values-sw600dp for portrait and values-sw600dp-land for landscape because 600dp is the "smallest width" that you have defined and 720dp. If you wanted, for example, drawables that are used on screens 1024dp or wider then you would create a directory called values-sw1024dp. The naming scheme is as follows: [resourcetype]-swdp-optionalFlag
Note: That optional flag tells the OS to only use resources for that specific instance. For example, the flag "-v21" means that it should only use those resources if the OS is API level 21 or greater.
Available Screen Width
values-w720dp-land
values-w720dp
These specify the minimum available width at which the resources should be used.
The Android docs describe it way better than I can...
This is often useful to determine whether to use a multi-pane layout, because even on a tablet device, you often won't want the same multi-pane layout for portrait orientation as you do for landscape. Thus, you can use this to specify the minimum width required for the layout, instead of using both the screen size and orientation qualifiers together.
Supporting Multiple Screens
Question 2 & 3
Do i need to programmaticly declare or just put @dimens/something in the layout xml?
You only need to put the above directories in your /res directory.
So, for example, your layout directories... you would put something like this in your /res directory:
layout
layout-land
layout-v14
layout-land-v14
layout-sw600-land
layout-sw600dp-land
and for your drawables you might have something like (for pre-3.2 support):
drawable
drawable-hdpi
drawable-hdpi-v11
drawable-mdpi
drawable-ldpi
and for your values:
values
values-v14
values-sw600dp
values-sw600dp-land
values-w820dp
values-w820dp-land
The both can work.
To support multiple screen size, the most common one used in res/value is dimens.xml. (the name of the file is just convention)
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
In other res/value-XXX, the value of activity_horizontal_margin in dimens.xml can be other to fit your need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With