android Manage Multiple screen sizes using dimens.xml - android

My first problem is, I am developing Android application where I want to manage the different screen sizes and display the data according to screen size. I have googled for it. Most of the people are saying to create the layout folder for different screen sizes(ex. layout-sw320, layout-sw480 etc..).
So I came up with another thought that I want to create only One layout, and create multiple dimens.xml file(ex. dimens-sw320.xml, dimens-sw480.xml etc..).
I created dimens.xml files like this four different widths(320dp, 480dp, 600dp, 720dp). But When I give dimensions for a textview It's not exactly displaying the ouput according to screen size. Can anyone here explain which dp size used for which screen size. Any help would be grateful.
Thanks in Advance...

Just create a Resource Directory for each category you want.
Project --> app --> res --> Right Click --> Add Resource Directory and select all the qualifiers you need.
For istance place the dimen.xml related to 720dp in values-w720dp directory.

Related

Layout adapting depending on Screen size

I have a problem with Android Studio when I have to adapt my application to different screen sizes. I tried creating diferent layouts depending on the screen size (small, normal, large, xlarge), but it doesn't work and I don't know why. No matter what the screen size of the mobile is, it uses the normal screen size layout. Here I leave you 2 screenshots: The first one is the res folder in the explorer, and the second one the folders in android studio.
Res folder
Android Studio folder
Try this approach:
//create a folder structure like this
/layout
/layout-sw300dp
/layout-sw400dp
/layout-sw600dp
/layout-sw800dp
Now you can place the respective layout files in the corresponding folders!
I hope this helps! Good luck!

Dimens.xml values supporting All Devices

Hello guys i know this is an old question but my requirement is different
i searched a lot and all answers are outdated not for xxxhdpi and tablets
I always create a new layout of each different screen and place it in respective folder it all works fine but in every project doing every layout is such a pain .so i came across the concept of dimens concept where you can place margins in dimens.xml in different values folder and our app will take it based on screen size
What i need is what are the exact folders i need to take and what should be the percentage of values in each folder some thing like this answer by salman
And if i give margin like
android:layout_marginTop="#dimen/dim_300"
If that button comes to centre in small screen ,it should also come in centre in xxxhdpi screen or any other device
and in dimens i will write some thing like this
<dimen name="dim_3">4.5dp</dimen>
i need answer in this format
folder name and percentage
values-sw480dp 2%
values-mdpi 1%
values-ldpi 0.75%
etc
thanks in advance

How to make UI in android for different devices

I'm fresher in Android & Coding. I have a task to design a popular game dots and boxes, for references https://en.wikipedia.org/wiki/Dots_and_Boxes . In this I have 7X7 cicles and used imageview to display all the stuff. My problem is how to design for multiple devices which looks as designed.
There is a great tool that lets you turn one image into multiple images for different screen densities: https://romannurik.github.io/AndroidAssetStudio/
There a few options there for generating the images, i use the Generic icons option since it allows an option for resizing the image.
if you use the generic option then:
Source: click image and upload the image (the circle for example).
Size and Padding: the defaults for size and padding are usually good enough.
Color: defaults to blue just move the seekbar to the far left in order to use the original color of the uploaded image.
Name and Download: at the bottom of the page you can rename the image see a preview and download as a zip.
Import: in the zipped file will be a res folder already structured properly by drawable densities and ready for you to just drag and drop into you /src/main folder.
P.S. Thank you to the person that made this tool your a genius and a life saver.
First of all use the unit dp for defining measurements. In addition to that, you have to define several values folders, where you define dimensions for scaling tablets or phones. E.g. define two values folders like:
values-large
values-xlarge
Now define a dimen.xml file inside this folders, where you can put your measurements in (unit dp) for the corresponding screensize. Define a measurement like this:
<dimen name="value1">17dp</dimen>
Then embedd this sizes in your layout xml, like:
android:layout_height="#dimen/value1"
Depending on the screensize, the system will load the correct measurements from this folders, e.g. if you have a screen size large only the defined values in folder values-large will be loaded. So instead of creating different layouts, define different measurements that can be loaded by the system automatically. For more information about this, also have a look at https://developer.android.com/distribute/essentials/quality/tablets.html

Relative "res/values" folder in Android to scale styles based on screen size and resolution?

I wonder if it's possible to have a folder such as res/values-small or res/values-hdpi in the same way that it's possible for the layout folder? I'm thinking about styles that should automatically scale depending on the screen resolution and size.
Or do I simply create a separate style for other resolutions in the same values/style.xml file?
Yes you are right all the names you mentioned are valid. To experiment more with different filenames use ADT.

Android: support multiple screens

I am trying to make a application in Android. I want that it should be able to run on multiple phones of different screen sizes, so i studied support multiple screen on developers and according to that i have to create 3 different xml files for supporting three different screen sizes and also 3 different types of images for each type of xml file. But on a blog i get the idea of doing this by using current screen size method. So i am confused what i should do. means which is optimized and performance increasing way. And which one will be more perfect for supporting all types of screen(except extra large screens)
Defining height, width and other parameters in the XML file is the better option rather than on run time.
Because XML files works as metadata (data carrier) to the activity and avoids alot of confusion when onCreate mothode in called.
Plus, create different folders for image quality (hdpi,xhdpi,ndpi,ldpi)
7 inch device use mhpi
10 inch devices use hdpi and xhdpi
While NEXUS tabs use hdpi and xhdpi irrespective of their size.
Mobiles use ldpi and ndpi.
Beauty lies here is that android device automatically pick-p the suitable content when found, i.e layout and image.
If not found it would first search other Layout folders,e.g a layout not found in x-large folder then it will search in large,then medium, small, which one of them suits the best ,(if a layout is not found in its respective folder).
Nexus will create alot of trouble for you.
To check how your layout would look on different devices, try using the options, which tells you how it would look on that device with those height width, present in the Graphical (view of a ) layout.
You can use three different layouts for different screen sizes ,and android will pick the suitable layout , but Using three different layouts for each type of screen format will not be a good idea , because it will cause problem in handling all layout , if screens are less then its fine but if number of screen increases it will get difficult . Like if you forget to add change in one of the screen size it shall crash with any exception .
What you can do is keep images of different size in different folders and practice layout to make standard in one layout by using layout weights , and margins in in dp .
See my this answer
Table Layout spacing issues
and check this layout will look similar for all screen sizes.
If your design is same for all screens sizes you can use dp and have only one xml for all screens.
But you should support icons for all screens.
I think it's less confusing David Ohanyan way, but forgot to say something...
Whenever you can, use styles in your xx_layout, images, etc, so you'll have 1 layout.xml and 3 styles files inside folders: values, values-small, layout-large.
At least for me, it's less confusing than opening 30 different layout files.

Categories

Resources