سؤال

What I have in my project is:

values-small;
values-normal;
valuse-large;
valuse-xlarge;

these folders contain the dimensions of the images and texts for all the screen sizes; But should I add hdpi,mdpi... although I've added the size of the image in dp, and the size of the text in sp..?

example:

 <dimen name="btnwidth">60dp</dimen>
    <dimen name="btnheight">60dp</dimen>
     <dimen name="fsinlistview">25sp</dimen>

because I am not getting the needed result on all the devices... So why the dp and sp aren't being fixed depending on the screen dpi?

هل كانت مفيدة؟

المحلول 2

The answer from @RahulGupta is pretty flawed. You should more follow what @amalBit has written.

As mentioned in my comment, the basic idea is to have a very flexible layout with some basic "cross screen" settings that you can and should follow

For example: The Settings list has on a phone maybe 16-32 dp margin on the sides, on a xlarge tablet like the Nexus 10 it has a way bigger margin. I highly doubt that the Settings screen was built with dozens of dimens files to fit all and every screen resolution, dimension and dpi. I guess that is basically just using one default for all and for the bigger tablets it is using a bigger value. So maybe a differenciation between 320dp and 720dp.

My suggestion: Start small with one layout, one dimens.xml file in your values folder and use a normal phone for your development. When you have done the layouting on it, check it on different screens and see if you need to modify something. Normally on a low res/low dpi device, the paddings/margins and sizes should scale correctly and in a good visual way.

The biggest "issues" you will face with 7"+ tablets and for them I would just start by creating a separate dimens.xml file and increase the dimens I need to make it better looking.

Normally the default values folder should contain 80% of your "style", the rest are just additions to make them fit perfect.

نصائح أخرى

Create a Single layout for default screens 4.7 inch (hdpi) in layout folder and dimensions in values folder. This is your superset.

Now let say you want your layouts for 7inch devices. Create values-sw320dp folder for 7inch in Portrain orientation

Now lets say you want your layouts for 10 inch devices Create values-dw720dp folder

NOTE :- For landscape just add "-land" in front of folder names.

Now lets say you have new devices such as Xperia SP (4.7' and XHDPI) and Nexus 5(5" and XXHDPI).

For these, you can create values-xhdpi and values-xxhdpi folders..

I hope you got the point of how to create folders..

Now your superset is defined in values folder. Most of the dimensions will be used from here only. Now run your app in other devices. Whatever mismatch is occuring just add that specific dimension in their respective values folder

Check this link Supporting multiple screens.

From the above link:

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).

Check out this converter.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top