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
Related
I'm working on android application and got in trouble of multiple screen support. I developed the app for 1080x1920 and when i tested the app on my friends Micromax Unite 2 with resolution of 480x800, it was something else. So i made two folders in the layout as:
layout-1080x1920
layout-480x800
thinking that the 480x800 device will pick up the layout-480x800 folder. But no it used the layout-1080x1920. So what should i do? So that the device having resolution of 480x800 works on layout-480x800
I suggest naming the folders as such:
layout-sw600dp
Where sw600dp means Screen Width 600dp. This layout folder will be used by devices with screen widths of 600dp or more (typically all 7-10 inch tablets, or just very dense screen). And when you are targeting for the phone use just the layout folder without any specified criteria. All phones not matching the sw600dp will use the default layout resources. Possibly also consider using
layout-sw600dp-port
if you need to use specific layouts for portrait orientation, likewise you can do
layout-sw600dp-land
if you wanted to specified layouts for landscape.
The link cricket_007 provided is where I learned this information
Note that 1080x1920 equates to about 540 x 960 dp in dp measurement, which is why I suggested to use the particular 600dp for width
giving the folder names pixel according to android screen support dev page. Even if you know all possible resolutions for every device, the android system takes those *xml files/drawables etc specified by their DPI, not PX. Those dpi resolutions still can change on runtime, such as, when your activity uses a tool bar (which is not part of your dpi resolution). Name your folders layout-xlarge, layout-large, layout-normal, layout-small for *xml layouts. I suggest to put 4 different xml files with same name in each of them and try it again for different devices.
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?
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
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.
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.
I'm really feeling confused. From the docs at developer.android.com, it seems in order to keep my images scaled correctly (aspect ratio too) across all current Android devices I need all these layouts below. Is that really what everyone is doing? Am I missing something, or should I be going about this a different way?
Low density Small screens QVGA 240x320
------------------------------------------------
layout-small-ldpi
layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
------------------------------------------------
layout-ldpi
layout-land-ldpi
Medium density Normal screens HVGA 320x480
------------------------------------------------
layout-mdpi
layout-land-mdpi
Medium density Large screens HVGA 320x480
------------------------------------------------
layout-large-mdpi
layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
------------------------------------------------
layout-hdpi
layout-land-hdpi
Xoom (medium density large but 1280x800 res)
------------------------------------------------
layout-xlarge
layout-xlarge-land
Your app will work on 100% of the devices with the classic layout.
You can just add some buttons or change the layout in landscape mode by adding some qualifiers but that's up to you!
For instance, on LDPI (small resolution) device, you may want to adjust some buttons or change a little bit to fit the small screen.
You may also want to put some buttons on the right in landscape mode and in the bottom of your layout in portrait!
You do not "have to" use them.
According to Android Dev Protip from Roman Nurik about screen size qualifiers:
If you have custom layouts for larger screen devices such as tablets,
now's the time to stop using the -large or -xlarge resource qualifier
and switch to using -swXXdp or -wXXdp qualifiers. The latter were
introduced in API level 13, which basically all tablets now have
support for according to the latest platform version charts1.
means that for basically all cases where -large would have any effect,
-swXXdp can be used instead to provide more granularity.
So which actual sw or w qualifiers should you use? Here's a quick
just-give-me-something starting point:
7" tablets: Instead of layout-large, use layout-sw600dp.
Example: Nexus 7 = 960×600 dp; the smaller of the two dimensions is
600.
10" tablets: Instead of layout-xlarge, use layout-sw720dp.
Example: Nexus 10 = 1280×800 dp; the smaller of the two dimensions is
800. Some 10" tablets are a bit more narrow so 720 is a commonly used switching point.
There's more to it than just that (you really want to choose switching
points based on your content's minimum requirements, not on device
form factor), but that's a #Protip for another day (::cough:: +Nick
Butcher ::cough::).
In the layout if you do not use AbsoluteLayout, you application is going to be resized to fit the screen.
But in some cases, for smaller screens you need declare a new layout with less components for example.
For images:
You has some options.
Simple ignore some resolutions and let the device choose the best image to it.
Declare on AndroidManifest for wich sizes you want to support.
Or has just one and let the resize screw your application.
Yes. You should define different layout for different screen resolution.
When you are supposed to work with tablet kind of application. That time really you feel that. There is a need of different layout. Because Tablets always comes in different size.
One more thing, When you are working on android, means you should always taste your app with real device. And also test with different size emulators.
I am trying to design different layouts for different screen sizes. I have created layout files for sw240dp, and I am now trying to design layouts for sw480dp. My problem involves the list of devices in the layout editor. I am trying to select a 3.7 inch device to design on, but the software keeps jumping over to the sw240dp layout file every time I select the 3.7 inch device for sw480dp. I don't understand what I'm doing wrong here. Is there something wrong with my eclipse software, or am I doing something wrong?
What resolution and density are you selecting for the emulated device? The DP is determined by the density and resolution. So for 480 DP, here is the mapping from density to required pixel resolution:
MDPI (160) : 480px
HDPI (240) : 720px
XHDPI(320) : 960px
So if you're picking a 3.7" 480x800 device at HDPI, that's not going to fall into the sw480dp bucket. You'd need to create it as an MDPI device (i.e. density of 160).
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.