I have an Activity with Grid View with 4 images. My Application focus on above Android version 3 and both Tablets and mobile. I want to know what is the actual image size i want to design to fit all screens. For example,What is the best image size for 7 inch tablet? In developer document said, based on dip , but i need actual each image size to fit on grid view(4 images) in 7 inch tablet.
in this case you have to create different layouts of your mainlayout. for an example . for 5.1 phones such as Galaxy Note you have to create new folder name it as layout-large and for 7.0 to 10.1 tablets you have to create new folder called layout-xlarge after creating these both folder paste your main xml inside them , and you'll see how your layout will look at 5.1 and tablets. this is the best way i came cross to make my images , layouts fits on all the screens. hope that helps you.
Dip x screen density = pixels (actual image size)
dp to px formula
displayMetrics = context.getResources().getDisplayMetrics();
return (int)((dp * displayMetrics.density) + 0.5);
As answered by Bram.
Related
I need to create two different layout folders based on this http://www.samsung.com/global/microsite/galaxytabs/specs.html specifications.
But I've seen that the two devices has the same display resolution and only difference is the size of the screen.
Is there a way to distinguish the two res folder?
on Android you can specify smallest width on the resources. Examples:
layout-sw600dp/ < that's a 7" like the Nexus 7
layout-sw720dp/ < that's a 10" like the Nexus 10
so all you have to do is to find out what's the smallest width in DP for the 8.4 inches (probably something around 660dp) and create the resource folder for it.
You can run this app on the tab 8.4 to find out it's size: https://play.google.com/store/apps/details?id=nl.qbus.sizemeup
Today, I read the android tutorial about supporting multiple screen. I got some problems here. In the tutorial, it says we can use size and density-specific resource in this way:
res/layout-w600dp/main_activity.xml
I know that w600dp means the available width is 600dp. But is it for portal or landscape?
Here is real case:
I want to design a full width header image for my android app in portal mode. This app is targeted for Samsung Galaxy S4, which has 5.0 inches, 1080x1920 pixels with 441 dpi. That means my header image need to be 1080 pixels. As android tutorial mentioned, in android, px = dp * (dpi/160); In Samsung Galaxy S4 example, 1080px width is 391dp. So do I need to declare the layout in:
res/layout-w391dp/main_activity.xml
or
res/layout-w320dp/main_activity.xml
When I am using Photoshop to create my header image, do I need to set my image parameter as 1080 width, 40 height and 441dpi? After I get the image, do I need to put this image in:
res/drawable-xhdpi/
or
res/drawable-w600dp/
The available width value will change when the orientation changes between landscape and portrait to match the current actual width.
If you want provide different layouts/resources for landscape and portrait add the qualifier name -land or -port respectively. See more at Android documentation
If you want fill all the available width don't think about dpi. If device width is 1080px then you need an image with 1080px. However, if you want an image look the same at diferent devices with diferent density then calculate its dimensions by applying these factors:
ldpi = 0.75
mdpi = 1
hdpi = 1.5
xhdpi = 2
xxhdpi = 3
It is not possible here to do a full explanation on this subject, and my English is not enough for such.
I know I can set a folder called layout-small, normal, etc.. for different screen sizes, but I want to set an specific folder for a tablet 9.7". Is it possible??
Referring to the DOC you can use layout-sw<dp>.
sw means "smallest width", and indicates the "shortest dimension of the available screen area". Usually 600 is for screens such as 600x1024 mdpi (7" tablet) and 720 for screens such as 720x1280 mdpi (10" tablet).
Based on the screen size of your tablet create your layout and put it in a folder named layout-sw720. Then test it directly with the emulator or your device.
layout-sw720 is for the 3.0+ 10 inch tab you can use it otherwise make a entirely different layout and pick it yourself at runtime based on screen width and height
I am developing for android and my code runs perfect on nexus or any 3.7 inch device.
If I run it on tablet (7 or 10.1 inch) then the fonts and buttons are very small and the spacing is way too big.
If I run it on 2.7 QVGA then the buttons are too big and overlap.
I am using dp and sp all over the layout so I am surprised it didn't adjust according to different screen size/density.
Does that mean that I have to wrte the same XML layout in 3 layout folders (large, medium and small) and put my drawable in 3 different density folders?
Or am I amissing something here. Yes I read the "Supporting multiple screen" document and it just loses me with the details (but I did follow the tips of using dp and sp). I am looking for more of a summary/general approach answer.
dp and sp adjusts according to screen density. Therefore, a screen with 500 dpi and 4000 dpi but with the same SCREEN DIMENTIONS will looks the same.
If they have different screen sizes, it won't fit as you want. If you want to support multiple screen sizes, you'd have to use weights or percentages.
The key is that dp = device independent pixel and it only adjusts according to density, not screen size.
In the most cases if you don't make a tablet app, you don't need to make more than one XML layout for different densities/sizes. All you must do is define dimensions with DP and SP as you said.
But is necessary to provide different images in the drawable folder to show one or other in function on screen size/density.
If you put all images in drawable folder (without specify hdi,ldi or mdi) Android will try to adjust the images but not always works fine.
Hope it helps.
I am new to designing interfaces for Android. (I have gone through the Multiple Screens section in the Developer Guide.) What base resolution are you designing your screens for?
That is based on your app is for phone, or tablet, or both. Currently when designing layout for phone's app, there are three most basic resolution:
- 320dip x 480dip (normally 320px x 480px phone)
- 320dip x 533dip (normally 480px x 800px phone)
- 320dip x 569dip (normally 480px x 854px phone)
So when you design layout for phone's app, please remember:
1. Always use dip for width, height and sp for text size
2. A layout fit 320dip x 480dip screen will fit the other two
3. match_parent, wrap_content, gravity... are powerful Android XML layout attributes
4. Choose the orientation (landscape, portrait) carefully, normally an app requires only one orientation
The same goes for tablet's app, choose the most normal screens and create layout for the smallest one, and stretch the layout on bigger one.
But for both tablet and phone, you should use dimens.xml to store layout values. Reference here: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension
Good luck with Android nightmare :)
Dont design for specific screen resolution!
Design for a range of devices either small screen, Medium screen or large screen.
Following are generic irrespective of your screen size.
Best layout is LinearLayout and RelativeLayout.
Bes metrics for Views 'dp' and for fonts 'sp'
Hope this helps!
I recommend base resolution for 320x480 pixel screen as this is supported by most number of devices. But you need to provide assets for hdpi (High Density), mdpi (medium density), ldpi (low density), xhdpi (xtra high density) specially images, buttons etc.