About Android layout - android

I am researching best practices for working with layouts in Android projects.
In the Android documentation says that from Android 3.2 to create qualifiers type -mdpi -hdpi etc is obsolete and that the best way is to create specific folders for each screen as sw600dp and etc. Also talks to create different layouts for each case, but how are the dimensions and images in this approach?
I create separate layouts for each case with fixed dimensions in the layout itself? How is that?
Images continue in folders like "dawable-mdpi"?
I spent some time studying the documentation but doubt continues ..
https://developer.android.com/guide/practices/screens_support.html

Correct me if I am wrong.
Before Android 3.0 drawable were placed in folders depending on the screen size. For supporting larger devices, putting drawable according to screen density was introduced. With this drawable were chosen depending on the pixel density of the screen and not just the size of the screen.
You can read about it in "How to Support Multiple Screens" section of this page https://developer.android.com/guide/practices/screens_support.html#support
So I think using small, normal, large, and xlarge is depreciated and we now use ldpi (low), mdpi (medium), hdpi (high), xhdpi extra-high), xxhdpi (extra-extra-high), and xxxhdpi (extra-extra-extra-high)
And sw600dp, sw720dp etc are for devices with screen dimension at least 600dp, 720dp etc. You can read more about it here: https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
You'll find answers to all your question in the documentation you spent some time studying. Go through it again, and I am sure things will be a lot more clear to you.

Related

How to handle images in low density large screens in Android?

I'm writing an Android app and have read up everything I can find on fragmentation and handling multiple screens, particularly from the official Android documentation.
I understand different screen densities utilize the various folders (mdpi, hdpi etc.) for images of varying sizes, and different screen sizes can utilize different layouts by defining them in res/layout-sw600dp layout-sw720dp etc. which all makes sense.
However, when developing my app my primary test device was a HTC Desire X phone 400x800 with 240dpi density and all looks well. I then tested it on a Prestigio Multipad 8.0 tablet and this is where I'm getting confused. The tablet has a screen size of 786x1232 BUT the screen density is only 160dpi. Owing to the fact that the screen density on the tablet is smaller, Android therefore uses the images in the mdpi folder for the tablet, and the slightly bigger ones in the hdpi folder for the phone! This therefore results in images way too small on the tablet.
I don't need to edit the layout for the tablet so the sw720dpi folders aren't a help.
What am I missing or not understanding properly here? How can I make my images scale up for the bigger, lower density tablet screen?
OK, I figured this out eventually. My mistake was I didn't realize drawables work exactly the same as layouts in that I could have a drawable-sw720dp folder which Android fetches the images from in the case of a screen with at least 720pixels of width. For completeness in the scenario I described I could have a drawable-sw720dp-mdpi folder in which to store my images.
I had an additional issue then whereby I had 2 copies of the same image in different drawable folders but I discovered you can reference images using an alias just like layouts. Details of how to do that can be found here.

Tool to convert layout dpi's for different screen densities

Are there any tools out there that can convert my dpi units for a baseline densitity into another?
When I define my layout-files I design for a screen with 320x480 dpi units. But then it doesn't fit right on small and large devices.
But since we know the baseline dpi's of ldpi, mdpi, hdpi and xhdpi, why isn't there a tool to just take my width/height definitions in the files and scale them to these different densities, given a default baseline. It should then return the missing layout files, where they would scale right on to these other densities.
It seems straight forward and would save developers tons of time, does anyone know of an existing program to do this?
I created a tool that allows you to scale/adjust your layouts for tablets and small screen devices and made a blog post about it here: http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html
Basically, defining your layouts in dp units is not enough if you want your app to fit on all devices and tablets, since there's four different "density-buckets". This tool will allow your layouts to be converted into fitting these density buckets.
I hope the blog, tool and answer will help others, I know it felt good to have my app work perfectly on a tablet with the press of a button.
Your question doesn't make any sense. what you're asking for is exactly what Android does.
If you put an image into a folder (like xhdpi) it is automatically scaled for all different device densities.
If you create a layout for a particular class of device, then the correct layout is used for the correct device.
I would advise against designing for specific resolutions of screen - there are too many. Group screens into buckets - e.g. "Phones" and "Tablets", or "Small Phones", "Phones", "Large Screen Devices" - specify criteria, and build layouts for each category. It's a fool's game to build layouts for every screen resolution, there are hundreds of Android devices.

Supporting all Android tablets resolutions

The designer of our company wants me to give him the resolutions of Android tablets so he will start designing a new app.
I know there are a lot of different resolutions (listed here: Android Tablets computers).
I also know about the division of Android to the different dpi's (ldpi, mdpi, ...).
My questions :
What should I tell the designer? He obviously not supposed to make a version for each resolution. Besides, some of the resolutions listed in the link above are in the same dpi, so which one should I choose?
Considering the fact the app is going to run only on tablets, what are the dpi classes I should use? Only hdpi and xhdpi? Or should I still use all 4 classes and limit the <supports-screens> tag in the manifest?
Is there a resolution that represent each of the dpi classes that I
should stick to?
I've done some reading about 9-patch. What's the point of using it if I still need to deliver a version for each dpi??
Thanks in advance!
The questions contain so much information.
1 Try to read the article and the references in it.
http://www.androiduipatterns.com/2011/11/design-patterns-for-responsive-android.html
You could also have a look at the web site for android design.
http://developer.android.com/design/index.html
In one word, designing for android tablets is more like designing websites. You cannot just design for one resolution.
2 Considering you are developing for tablets, it's necessary to support mdpi and hdpi. If the apps could be installed on phones, maybe xhdpi is also needed. It's not very strict.
3 dpi(dots per inch) = pixels per inch. So dpi is like density, it do not have strict relationship with resolution. But there is still a sheet could help you, try to find it in the following page
http://developer.android.com/guide/practices/screens_support.html
4 9-patch resource is very useful. With which a small png could stretch to any size without distortion. And it could also help to reduce the size of your resources.
In most situation, you do not have to make 9-patch for each dpi, since it could stretch to any size you want. But if the 9-patch png contain some information itself, like min height and padding, it's necessary to make different versions.
Here is what I would do:
See what combinations you have. There are mostly 3 resolutions for tablets (1280x800, 1024x600, 800x480) and mostly 2 densities (hdpi and mdpi). That is at most 6 versions. Select a few matching your most logical targets (I would choose xlarge mdpi (9" 1280x800), large mdpi (7" 1024x600) and normal-hdpi (4-5" 800x480) and design on these.
Some graphical elements don't need to be designed for each combinations, like backgrounds, may be buttons… Here comes the 9-patch. To be put in drawable-nodpi folder. One resource fits all.
Do one version first on you major target, then see how it fits on the other targets, and consider adjustments from there.
Use ScrollViews if you don't want to position every item pixel-perfectly on each device.

I am confused with drawable-hdpi and drawable-mdpi

i am attempting to get my android app to work on both phone type devices and tablets. for the layouts i have layout-normal and layout-large and i place my xml files inside each and it seems to select the correct one for each device (layout-normal for phones and layout-large for tablets).
however the problem arises for the drawable folders. i have drawable-hdpi, drawable-mdpi and drawable-ldpi. the tablet is taking its images from the drawable-mdpi, and the phone is taking its images from the drawable-hdpi. from the reading i have been doing this seems to be backwards??? this seems to happen on both the emulator and real devices, could i be doing something wrong? am i mixing something up?
Clayton,
drawable-hdpi and drawable-mdpi is not related to the size of the screen itself, but to the resolution of the display.
It's probably easy to think in terms of the iPhone 3GS and 4 for this (bear with me please). The 4 has retina display, hence a much higher resolution. Using the same sprites you'd use with the 3GS would result in a blurry display.
Android phones are, if anything, much more diverse in terms of screen options.
If you want to be able to aim different layouts at different resolutions, please try putting the layouts into /layout-xlarge, /layout-large, etc...
You can find more here:
http://developer.android.com/guide/practices/screens_support.html
There are some changes that you can see for Android 3.2 and above:
Beginning with Android 3.2 (API level 13), the above size groups are
deprecated and you should instead use the swdp configuration
qualifier to define the smallest available width required by your
layout resources. For example, if your multi-pane tablet layout
requires at least 600dp of screen width, you should place it in
layout-sw600dp/. Using the new techniques for declaring layout
resources is discussed further in the section about Declaring Tablet
Layouts for Android 3.2.
ldpi, mdpi, and hdpi refer to pixel density, not screen size.
The accepted answer does not address a serious problem: if you have many drawables, you end up with an unnecessarily big apk file because of resource duplicating. The only solution for that is the resource alias option described here:
http://blog.evendanan.net/2011/03/Android-resources-and-device-fragmentation
Edit: I just beheld that OP didn't realize that most phones have hdpi density, while most tablets have mdpi density. At the same time the tablets mostly have higher resolution. Hence Android will use smaller pictures for higher resolution.
You can overcome this only by using vector images or using the methods described in the accepted answer and in my answer.
drawable-hdpi - application use this drawable images when the device has high pixel density
drawable-mdpi - application use this drawable images when the device has medium pixel density
drawable-ldpi.-application use this drawable images when the device has low pixel density

Android - Screen Resolution and Screen Density

As per managing resources(images) in > Android 1.6 version, we need to keep different-resolutions image in Drawable-Hdpi, Drawable-Mdpi, Drawable-Lpi folder particularly.
And as per this page: http://developer.android.com/guide/practices/screens_support.html ,
In Low density section - there are three resolutions used: 240*320 , 240x400 , 240x432 for the Small screen, Normal Screen, Large Screen particularly.
same way for Medium density section - there are three resolutions used: 320x480 , 480x800 , 480x854 for the Small screen, Normal Screen, Large Screen particularly.
and same way for High density ........
but i am confused here:
(1) How do i come to know that whether small, Normal or Large screen is used, i mean is there any way to know ?
(2) How do i come to know which type of density i am using ?
(3) And in Drawable-Hdpi, Drawable-Mdpi, Drawable-ldpi folder, which resolution's image we should keep particularly?
There are specific Android API calls that can, at runtime tell you what density and (small/large/normal) screen size a handset has. However, as a developer we should not need to worry about individual handsets at all. All we need to do is to have ldpi/mdpi/hdpi assets and small/normal/large layouts in the apk. Android internally handles everything.
Dont forget to get an indepth understanding of how Android determines which assets to use and aliasing here.
Why do you want to know the actual density? It's Android's business. But I'm sure there is a way to retrieve this information.
For development I put everything in the hdpi-folder. I also could put everything in a general Drawable Folder.
At the time u publish u can decide if u want to provide already downscaled resources for ldpi and mdpi. However, thats not necessary.
Update: Retrieve actual density with this class and best practices
Update 2: I found a 25 min video from Motorola discussing all those issues: Working with multiple screens
1) Change the content of the layout in different folders i.e layout-small, layout-large, etc Now test it in Different emulator with different screen resolution.
2) For Finding out density of the Device use
Log.d("Density", "" + (getResources().getDisplayMetrics().density));

Categories

Resources