How to arrange images in different drawable folders? - android

I know the discussion about this is available everywhere and I myself have worked with these folders, but still after reading them I recently I had a big confusion regarding how to arrange images in drawable folders -
Look at this XML File -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/wallpaper_chapter_selection"
tools:context="com.greenloop.joindotsandpaint.ChapterSelection">
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="#drawable/img2"
android:padding="20dp" />
<RelativeLayout
Let's consider 2 phones regarding this Landscape Mode -
Nexus 10 - 2560 px * 1600px xhdpi
Nexus 5 - 1920px * 1080px xxhdpi
In the case of Nexus 10 - Image size will be 1600px (height)
And in the case of Nexus 5 - Image size will be 1080px
Image size required by Nexus 10 will be greater than that required by Nexus 5, But nexus 10 will take image from the xhdpi folder (smaller image size) as it is xhdpi
and nexus 5 will take image from xxhdpi folder.
So how should I work around this. I have lots of similar layouts in which I am facing a similar problem.

The drawable-hdpi, drawable-xhdpi, drawable-xxhdpi etc. specifies only the dpi dimension and devices of all sizes are going to get resources from the same folder as long as they have the same dpi specifications. To add the screen size dimension you can add large (for devices 7" and around), xlarge(for devices 10" and around) etc. to this. For example you can have a drawable-xlarge-xhdpi to force the Nexus 10" to get a particular resource from this folder. Or your can have only drawable-xlarge and this way all the 10" devices will pull the resources from this folder, no matter what their dpi is.
Basically the one-catch-all is the drawable folder and you overwrite on a case by case basis with the values from drawable-*-*-etc. folders.

Check the part under "Screen size":
http://developer.android.com/guide/topics/resources/providing-resources.html
You can (or rather need to) create different layouts for different screen sizes. Phones and tablets are treated differently.
The Nexus 5 has a higher DPI. 1080px on 5" VS 1600px on 10"... So it is correct that Nexus 5 uses the xxhdpi resource (here: image!) and Nexus 10 the xhdpi. (xhdpi isn't "bigger" than xxhdpi, it just "has less" pixel per inch).
Layouts for phones and tablets are something different to DPI of screens.

Related

Properly defining dimens.xml to support both Android mobile and tablet devices

I have an app in the play store which runs on all mobiles and now I want to release it on tablets as well.
1) The images have been designed for xhdpi screens. So I think that will be sufficient to support tablets as well or should I redesign the images seperately for tablets?
2) I want to split dimens.xml into 3 categories -
dimens.xml for all mobile phones
dimens.xml for all 7 inch tablets
dimens.xml for all 10 inch tablets
The solution I came up with is divide the values folder like below -
values/dimens.xml
values-sw620dp/dimens.xml
values-sw720dp/dimens.xml
but since few mobile phones might fall into values-sw620dp/dimens.xml or values-sw720dp/dimens.xml, What is the appropriate way to divide dimens.xml into 3 categories??
Please do not post the below picture as I want to divide into 3 categories
Following is Struture Answered by Many
1) There is no tablet device in the market with higher density than xhdpi. Therefore, xhdpi images are sufficient to support tablets
2) Dividing the values folder as below will be helpful
- values\dimens.xml
- values-land\dimens.xml
- values-sw600dp\dimens.xml
- values-sw600dp-land\dimens.xml
- values-sw720dp\dimens.xml
- values-sw720dp-land\dimens.xml
The suffix -land is used for lanscape orientation.
Mobile phones do not fall into the sw600dp or sw720dp category. I think you are confused between dp and px.
Example:
Take Samsung Galaxy S7 Edge.
Resolution : 1440 x 2560px
Density : xxxhdpi
Converting 1440px to dp at xxxhdpi density, you get 320dp (Convert px to dp)
Therfore the width of Samsung Galaxy S7 edge in dp is 320dp and will fall in values\dimens.xml file
If you take a Tab and find dp similarly, you will notice that the dp will be greater than or equal to 600dp.

Android 7" & 10" Tablets Layouts - sw600dp & sw720dp

I have created an android application that is working fine in the mobile handsets. Now I want it to be compatible for 7" and 10" tablets as well. For this I have created drawable folders as well as layout folders (sw600dp for 7 and sw720dp for 10).
There are many 7 inches tablets in the market. With different pixel as well as screen density.
For instance - 7 inch tablets range from Width x Height (600 X 1024) to (1200 x 1920) with PPI ranging from 170 to 323.
Similarty 10 inch tablets range from Width x Height (768 X 1280) to (1600 x 2560) with PPI ranging from 132 to 300.
I have created my image resources in the sw600dp and sw720dp considering the base size of the 7 and 10 inch tablets which is 600 x 1024 and 768 x 1280. I have designed my layouts in a way that my application looks fine in both these pixel and PPI densities.
BUT WHAT ABOUT THE REST OF THE DEVICES?
I need a way to make sure that my application looks great on all the 7 and 10 inches tablets available in the market. How do I achieve this?
Google has recommended that developer should focus on the density of the device rather its size but here problem is that If I try the DisplayMetrics to find the density of the current device and show my drawable and layouts accordingly - possibility is that I might display wrong drawable in wrong layouts since the PPI range of 7 inch (170 - 323) and 10 inch (132 - 300) overlap with each other.
How do I make sure to display right drawable and layouts for the current device? Do I need to create multiple drawable and layouts folders for the 7 inch and 10 inch tablets or will 2 drawable and 2 layouts (sw600dp and sw720dp) will suffice for this?
Kindly suggest as I am facing this problem for many days now. TIA.
First of all, you don't need to check DisplayMetrics for all the devices. You need not worry about the "actual screen density"; instead look for the "generalized density".
From the docs,
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
You need to specify your layouts and drawables in their appropriate density specific folder to get them right on the different devices.
For example, you have some image to show, then create copies of that image with different dimensions (small size image for small display, large size image for large display). Once you get these images ready then put them into the density folders (for drawables it will be drawable-hdpi/, drawable-mdpi/ etc). Thats it. Now when your app runs, system will detect the screen density and will take the image from appropriate folder.
For details on this, read Supporting Multiple Screens.

Drawable folder for 8 inch tablets

I am working in an android application and I want to support my application in all devices. But I don't know from which drawable folder 8 inch tablet takes images.
"drawable-mdpi" for mobiles, containing 320px-width images
"drawable-hdpi" for mobiles, containing 480px-width images
"drawable-xhdpi" for mobiles, containing 720px-width images
"drawable-sw600dp" for 7'' tablets, containing 600px-width images
"drawable-sw720dp" for 10'' tablets, containing 720px-width images
???? for 8'' tablets
You can use : "drawable-sw720dp" for 10'' tablets, containing 720px-width images" for the 8" Tablet .
For more info you can refer here , as 8" is reside between 7-10 Range so that you can use 10" drawable folder
http://developer.android.com/guide/practices/screens_support.html
"drawable-sw600dp" for 7'' tablets, containing 600px-width images
"drawable-sw600dp" is the folder that applies the drawable properties of device with minimum 600dp width.
So you dont need to worry about it.The android system will automatically suites drawable from sw600dp to 8 Inch Tablets
Have a Nice Day ....
The qualifiers hdpi,xhdpi,xxhdpi describes the screen density of the device, not the size of screen. From the official doc
The better practice is to put the following drawables
// for Phones
drawable-ldpi
drawable-mdpi
drawable-hdpi
//for 7 inch tablets
drawable-large-mdpi
drawable-large-hdpi(for Nexus 7)
// for 10 inch tablets
drawable-xlarge-mdpi
The drawable for 8" inches should be implemented if the App uses large background images where should be taken in a serious importance for memory allocation.
U can easily categorize your Drawables to large-mdpi, large-xhdpi , large-port-xhdpi(..) but u are in a situation where u delete the small , normal large and u implementing a swallest width of 600, 720 as any android delevopers will customize early or later.. I really suggest to implement an sw800 where has 1280 x 800!!! and also to make sure in your code to have an ifstatement where directly speaks throw the DisplayMetrics.Density and implements == to 800 widthPixels... This will give an HD performance if the images are recycling and are on in InBitmap to retain instance..

Android 2.2 - screen resolutions and sizes issue

The android version is 2.2. And the apps will not support drawable-xhdpi with drawable-xlarge folder. However, i have met many issue when I am processing different screen size from different mobile.
The first problem is that I want to know what is the situation that android will load correct image from drawable-ldpi, drawable-mdpi, drawable-hdpi folder? There are one image in each folder (drawable-ldpi, drawable-mdpi, drawable-hdpi).
(1) 240px x 150px for drawable-ldpi
(2) 320px x 200px for drawable-mdpi
(3) 480px x 300px for drawable-hdpi
But why i cannot see correct image if the output device width screen is 480px? The output device only shown 320px width image. Not the 480px image. The issue seems that what the thing i have missing?
Then, i renamed all drawable folder to drawable-small, drawable-normal, drawable-large. It is working that drawable-large can display 480px width image. Will it be good if i do this way?
The second issue is that some samsung device have got different screen resolutions, i would like to know how to support these screen resolution as I want to make 800px width screen displays 800px width image, 900px width screen displays 900px width image? Any method can do different screen resolution? Many people said the folder drawable-xhdpi can solve issue that image can be auto-scaling. I cannot see any image can be auto-scaling. Maybe i have missing some steps.
Kindly advise.
Thanks a lot.
I will try to give you better insight into this.
Screens can be divided into more or less 4 different categories:
Low-density
medium-density (Baseline)
high-density
extra-high-density
You also get xxhdpi these days...
low-density = ldpi (120dpi)
medium-density = mdpi (160dpi)
high-density = hdpi (240dpi)
extra-high-density = xhdpi (320dpi)
Another good example comes from the android developer pages:
http://developer.android.com/images/screens_support/screens-ranges.png
You can find a list of devices and their pixel densities here:
h ttp://en.wikipedia.org/wiki/List_of_displays_by_pixel_density
h ttp://checkscreensize.appspot.com/listdevice.jsp
You will always be designing apps with multiple layouts/drawables to support different devices. Not just Samsung devices, but most brands have different devices with different pixel densities and resolutions.
In short, by providing multiple resources, android will choose the correct one to best fit the current device and if it does not find one in a certain layout or drawable folder, it will simply use the next best layout/resource with that name.
Note, this is to avoid stretching and incorrect scaling of drawables and layouts.
How to support multiple layouts ?
in your manifest file.
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Provide different layouts or drawables for different screen sizes.
Now, there are multiple ways of doing this and some ways are dependent on the sdk level.
Pre Android 3.2 / API 13 , use layout-small/normal/large/xlarge.
After Android 3.2 / API 13 , use layout-hdpi, or layout-sw600dp etc.
Here is the official table of qualifiers you can use, by placing a dash between them:
http://developer.android.com/guide/practices/screens_support.html#qualifiers
Generally, I think that you will only design for landscape mode with tablets, therefore, you could consider using only these and:
layout-ldpi
layout-mdpi
layout-hdpi
layout-xhdpi
layout-large
layout-large-land
layout-xlarge
layout-xlarge-land
and for your drawables:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
Further, by default, I currently choose to design for 6 different devices that overall fits best in the profiles ldpi, mdpi, hdpi, xhdpi for phones (4) and tablets (2):
Samsung Galaxy S3 (720x1280, xhdpi, Normal screen size)
Samsung Galaxy S2 (480x800, hdpi, Normal screen size)
Samsung Galaxy Ace Plus (320x480, mdpi, Normal screen size)
Samsung Galaxy Mini (240x320, ldpi, Normal screen size)
Samsung Galaxy Tab 10.1 (800x1280, mdpi, X-Large screen size)
Samsung Galaxy Tab 7.0 (600x1024, hdpi, Large screen size)
Designing for these devices ensures that the app will work great on most other devices aswell.
Hope this information helped.

Android, mdpi density but different screens

I am working on an application that will run on multiple devices. I have three devices for testing.
HTC Desire S -- 480 x 800 pixels, 3.7 inches (~252 ppi pixel density)
Samsung P6200 Galaxy Tab 7.0 Plus -- 600 x 1024 pixels, 7.0 inches
(~170 ppi pixel density)
Samsung Galaxy Tab 2 10.1 P5100 -- 800 x 1280 pixels, 10.1 inches
(~149 ppi pixel density)
As per my understanding if i correctly develop my application for above three, most of the other devices will be handled. may be?
My question is from where should i start designing my images? As the both tablets are of mdpi density but different screen sizes, i designed the images for TAB2 and placed the images in drawable-mdpi directory, those images were shown perfectly on TAB2 but on TAB7, things are messed up, images are overlapping on each other.
So, both the tablets are mdpi and for mdpi, images should be placed in drawable-mdpi but for which tablet size should i design images?
Application UI usually is not fully bitmapped. You got some elements like icons which are fixed size, but from other hand your buttons should scale without problems. So assuming you want to target all devices, you should design your UI the way it fit on smallest supported screen (in this case 600 x 1024 pixels is your max) - this means that if you preview on said screen all UI elements are fully fit on screen. On higher screens you UI have to scale, but this usually do not need any special approach (unless you work on bitmapped game for example) as elements like lists, buttons, layouts will stretch automatically. And if your design assume any bitmaps involved in said scalable elements, use 9-patch PNG files to make it scale correctly.
For more on that subject, please read "Supporting Multiple Screens".
I recommend you designing for xhdpi, you can allways resize for lower dpis.
Take into account dpi is not related to screen size, on the other side, larger screen tablets have lower dpi than most "modern" phones.
Make the layout for target screen sizes, i.e. 10" and 7" tablets, the system will take the best bitmap for your device dpis (or restcale the nearest one!).
With the latest (beta) Android SDK and Eclipse plugin you'll take a better view of the differents devices screens: dpi + pixel resolutions + screen size., they now show, for exaple, like
7" WSXVG (Tablet) (1024x600: mdpi)
in the layout editor.

Categories

Resources