Layouts on different models of mobiles - android

Recently i develop an app for Galaxy 10.1 ,7 inch with 1024x600 ,480x800,Note with 800 height abd S3 with 720 height. they are all running perfectly on these resolution. But when we talk about note 2 and galaxy 7 plus and other we got several issues .Which are that the layouts are not correctly seen on these devices. At that iam facing a problem in layouts i use layouts folder for note as layouts-normal-xhdpi-1280x800 and for S3 layouts-normal-xhdpi-1280x720 and put all the layouts in one folder which makes one apk supporting all these layouts.
But when customers download the apk they deal with a problem which was that the Galaxy note picking the layout-normal-xhpi-1280x720 layouts and it was right but S3 and Galaxy Note 2 have different density .
Because of that problem I can't figure out how to declare layout folder for S3 and Note 2.
Is there any way that i use only default four folders
Layout Xlarge
Layout Xhdpi with normal
Layout mdpi
Layout hdpi with normal
and supports these all layouts for all screen like S3 ,note 1, note 2, 7 inch plus and others. When i try to start my project i always thought about the big famous games like one of these is "Temple Run" which runs on all mobiles and tabs.
Making bunch of layouts folder make my app heavy like it crosses 80MB limit and Google market only accepts less than 50MB apps.
Pro grammatically is there any way that we use only one layout folder and support this layout on all screens.
I read number of articles and android developer portal but they did not satisfy me.They all said you have to make different layouts folder for different screens and even on stackoverflow i saw the same situation for saving my time in first projects
I use these techniques but my work is now increasing day by day and i want that i start with those techniques which make my app not heavy because of these bunch of layouts plus not waste my time in making number of layouts for numbers of app.
Number of helps will be appreciated and i want answers and suggestions because these problems are faced by number of developers which are new and others also.

I am also facing such problem in my application. But i found a good solution for this.
I have only one layout for tablet and directory name is layout-sw600dp.
Now, when part came to height and width problems, I have created several different values directory in which i place dimensions and font size and other stubs. So there will be no constant value in layout of tablet screen.
androd:layout_width:"60dp" // i drop this scenario
androd:layout_width:"#dimen/tab_width" // i used this scenario
and your values directory name will be like
values-xlarge
values-large
All the values will be fetched from your values directory. It will not create different layout, but one layout can be used multiple times.
Edit:
Following are words of Developer.android site.
Configuration examples
To help you target some of your designs for different types of devices, here are some numbers for typical screen widths:
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).
Using the size qualifiers from table 2, your application can switch between your different layout resources for handsets and tablets using any number you want for width and/or height. For example, if 600dp is the smallest available width supported by your tablet layout, you can provide these two sets of layouts:
res/layout/main_activity.xml # For handsets
res/layout-sw600dp/main_activity.xml # For tablets
===
In this, you can see that, layout for 1280*720 is under layout-sw720dp so instead of creating layout-normal-xlarge you should use this thing which lets you to decide differences. Instead of identify differently using layout-large-mdpi and layout-large-ldpi, are't you just identify by its smallest width? Because, android providing drawables directory for different images, only thing is its resolution. And you have above solution.

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.

Android Phone and Tablet UI

I have made one app which is working fine for both Tablets and Phones. But as we know we should have a different layout for tablets( such as bigger font and images etc).
My question is how to provide the layouts such that they are only picked by tablets and not phones.
Example: If i provide xhdpi or hdpi layout thinking of these as tablet then it may be picked by some device also which is using this same configuration.
So how to be sure that a current device is tablet or phone and provide a specific layout for it?
My question is how to provide the layouts such that they are only picked by tablets and not phones.
Either use the classic screen size buckets (e.g., res/layout-large/) or come up with your own buckets using -swNNNdp (e.g., res/layout-sw600dp/ for resources to be used on devices whose shortest width is 600dp or higher).
This is explained in the documentation here, here, here, and perhaps a few other spots as well.
Example: If i provide xhdpi or hdpi layout thinking of these as tablet then it may be picked by some device also which is using this same configuration.
-xhdpi and -hdpi are screen densities and have nothing directly to do with screen size.

Designing layouts for phones and tablets

Okay i am familiar with this site and what it says
http://developer.android.com/guide/practices/screens_support.html
But im still having a problem.
I am designing layouts for phones and tablets from gingerbread to jelly bean.
I had started with a basic layout folder and designed everything for a galaxy nexus phone. now im going back and adding tablets. one question here is should i use layout-xlarge/layout-large or layout-sw600dp/layout-sw720dp? im guessing the smallest width is what i should be using.
But thats not the issue.
This issue is im trying to do that layous for Galaxy Nexus (720x1280) and Nexus S (480x800) These are much different yet eclipse doesn't seem to let me differentiate.
So i just want to be clear on what i should be doing to do this right. is this what i should have to cover the devices i want to?
layout-hdpi
layout-xhdpi
layout-sw600dp (instead of layout-large)
layout-sw720dp (instead of layout-xlarge)
will doing those layout-hdpi and layout-xhdpi separate the layouts for a Nexus S and Galaxy Nexus?
First, the layout-sw are based on dp, Density-independent pixels, rather than pixels. You can think of dp as 'actual size' pixels i.e., 1dp is the same physical size no matter what device is being used.
Therefore the Galaxy Nexus, which has a 720x1280 pixel screen is only 360x640 dp resolution and there is no overlap between a phone and the higher sw600+ folders.
The large/xlarge buckets will continue to work on all tablets, but if you need finer grained support or alright only using tablet layouts on Android 3.2+ devices, then you only need the sw--dp folders. You can also use both without copy/pasting your XML by using a reference file, as detailed in the below blog post.
More details on how to support multiple screens can be found in Supporting Multiple Screens guide and some of the reasoning behind why you'd want to use the new sw---dp buckets can be found on the Android Developers blog post announcing the feature.
Just use layout-large and layout-xlarge. When you're developing the layouts and want to know what it looks like on a certain device, just change the view and it will pull the appropriate XML from the correct folder.

With Android, is it possible to have different layouts for phones and tablets?

ok, I know that most current phones and a 7 inch tablet are both considered "large" as far as screen size according to Android. But there's a big difference between a "large" phone with 480x800 pixels and a "large" 7 inch tablet with 800x1280 pixels. I've created separate layouts for those two sizes, but I still haven't wrapped my head around how to get the phone to see the 480x800 layout and have the tablet see the 800x1280 layout. I've tried tweaking the res folder names to things like layout-large-hdpi and layout-large-mdpi, and also leaving the smaller phone layout as layout and the larger, tablet layout as layout-sw600dp as the Declaring Tablet Layouts for Android 3.2 page suggests, but the problem there becomes Android is still looking in the drawable-hdpi for the phone sized images. So the question then is: How do I declare the phone layouts, and have the phone layout look in the phone drawables folder, and declare the tablet layout and have the layout look in the tablet drawables folder? I'm targeting Android 3.2 with this app that I'm working on.
Sounds like you're on the right track.
Stick your phone layouts just in "layout".
Stick your 10" tablet layouts in "layout-sw720dp"
Then use "layout-sw600dp" for targeting 7-inch devices.
You can use the same suffixes for the drawable folders to, so drawable-sw600dp would be targeted at 7" devices. [Reference].

how can i develop application for all android devices ? what setting can i put on simulator that work on most devices?

What simulator resolution i should keep when developing application for Samsung galaxy s2 and galaxy s3 ?
What i found that samsung galaxy s2 has 480x800 resolution and s3 has 1280x720 resolution so what i have understood up till now that I should ask my graphics designer to provide me hdpi graphics that contain 480x800 background images and to implement same background image in galaxy s3 mobile, I will use image of size 1280x720 and put in xhdpi folder so that it can work on s3.
The background image is something which covers whole available area for mobile app. so am i right ??
You will need to create several emulators or get various devices.
There are some pretty important ones, so generally you need to make sure you have:
ldpi, mdpi, hdpi, xhdpi
and
small, medium, large, xlarge
Some people choose to exclude certain sizes (like small and ldpi) but htat's up to you,
if you go with some or all of the following, it should be a good start:
480x320 (SE Mini 10), 480x800 (GS2, Desire, etc), 1280x720 (GS3, Galaxy Nexus etc), 1280x800 (Note, Xoom, various other tablets)
HTC ChaCha (because it's landscape default)
You need to make sure you create resources in the relevant folders for each density, usually, I tend to ignore ldpi and just put resources in:
mdpi,hdpi and xhdpi (mdpi will be scaled down for ldpi devices,
automatically)
You may also need to create various portrait and landscape layouts in different sizes.
Reading this page provides most of the necessary information:
http://developer.android.com/guide/practices/screens_support.html
This page also contains important information regarding size distribution and popularity that is constantly up to date:
Android Stats
One thing that Android does for you is that it manages resolution. If you use the proper size formats (dp, sp, etc), your layout will scale to almost all resolutions. If you place images in the proper drawable folders (hdpi, ldpi, mdpi, etc), the OS will also swap those out as necessary.
Also, the emulator should handle resolutions for specific devices, if I recall correctly.
Desing lazout in smart way! Usualy it means don't put to mutch content in one layout.
Make sure that evrything looks good on smallest size and bigest size. It is better to treat tablets separetly. Read how providing alternative resources works, you can build sepereate layouts for each screen size.
Check if the hardware is available on that device before using it. hasSystemFeature() can be used for checking.

Categories

Resources