Android Virtual Device detects wrong screen size - android

I have been working with programmatic layout in Android Studio and i have a problem:
AVD always uses normal layout even if i use Nexus 7 which has "large" screen as its property
it is not code problem, since when i plug in my tablet it uses large layout and works fine
Any ideas where the problem might come from?

Well you are right in some sense android should take layout dependent on different densities but some mobile do not fall under specific density. Therefore android will pick up default layout from layout directory.
to support multiple screen resolution provide different layout for different screen sizes, you can make following directories in res directory like this
layout-hdpi
layout-mdpi
layout-xhdpi
layout-xxhdpi
layout-w320dp-h408dp
layout-w480dp-h800dp
layout-w480dp-h854dp
layout-w720dp-h1280dp
layout-w1080dp-h1920dp
layout-w1440dp-h2560dp
when you provide layout in all this directories you will give multiple screen support for different sizes as well

Related

Why is my device with "normal" screen dividied by Android studio as "small" screen device?

I have that problem:
i have two layout folders layout-small and layout
When i change rendering device on preview when editing layout to Nexus S (It have "normal" screen) Android studio will open the layout-small and let me edit small screen layout which is displayed on Nexus S.
Same issues with other "normal" screen devices
thank you for your answers.
I had the same problem.
Try to rename your "layout" in "layout-normal". In this way Android Studio recognizes the right layout type for "normal-sized" devices and assigns the "layout-small" just to Android Wear devices.
My advice to set a well formatted "layout-normal" is to design it on the smallest device available for "layout-normal" (Nexus One 3,7").
From android documentation: Supporting Multiple Screens
As you can see in this image, a device's actual size is not certain to belong to either small or normal. Some sizes belong to both categories. Also please note that on android's manifest setting targetSdk may affect the judgement.

Eclipse problems with different Android Layouts

I created a special layout for one of my activities in the /layout-small folder. The problem is that when I open my default layout (the one for which I have the small version), Eclipse decides to open the small version instead! At this point I go back the 'normal' layout but it's displayed for a 2.7" screen and if I make any change to visualize it in any other screen size Eclipse decides to send me to my 'small' layout while keeping the default one at 2.7". I can change my small layout to any size I want but that really makes no sense at all!
Any help is appreciated. Project CLEAN and restarting Eclipse I already tried.
I also had your problem for managing different screen sizes. The one that I use most frequently is to reorganize my layout folders in the same order as drawables. By this I mean that I create these folders for layout :
layout-ldpi
layout-mdpi
layout-hdpi
layout-xhdpi
If you open a layout file from the "layout-hdpi" folder , the default device for displaying the preview will be an hdpi one , like "4.0 480*800 hdpi".
Also. I found it much more time-consuming when adapting to different screens.
Another workaround that I'm really in favor of, is using the Intellij Community Edition for android development and user interface design. Intellij is a very stable and robust IDE based on gradle and is much much smoother than the buggy Eclipse.
If you are still having layout issues then I suggest reading this:
http://developer.android.com/guide/practices/screens_support.html
As of API level 13 layout-small/normal/large have been deprecated and you should be using sw<>dp qualifiers.
I have an app that has multiple layouts and my standard layout file is for screens that have the smallest available width like so:
layout (smallest screens)
layout-sw480dp (screens that are slightly larger)
layout-sw600dp (7" tablets)
layout-sw720dp (10" tablets)

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.

Layout for unusual screens

Some of users downloading my apps complain that they were unable to install the app as it exited with MainActivity.class layout not being found. After investigating, I realized that those mobile phones have unusual screens.
For example, one of those phones is HTC ChaCha which screen is 480 x 320 pixels, 2.6 inches (~222 ppi pixel density). According to these specifications, it is a Normal screen, MDPI.
However, as its screen is set in the landscape mode (wide mobile screen), Android does not recognize it as Normal MDPI, but as something else and then it tries to pull XML layout from /layout dir. The Main.xml layout in this directory does not envisage such unusual screens and the layout gets broken (layout icons too big and probably pulled from HDPI drawable directory).
How to make the XML layout for such unusual phones?
PS. One more Question. When I create an emulator for this phone via Android SDK Manager, should I set "Abstracted LCD density" to 222 or keep it to 160???
The problem of the HTC Chacha is in fact it's screen aspect.
It's a "notlong" screen (like the HTC Wildfire if I'm correct).
To make a specific layout for this phone (and all screens with a 4/3 ratio), just make a layout in layout-notlong directory.
res
|---layout-notlong
|----mylayout.xml
Are you sure that the error is that the activity's class can't be found?
Several device vendors will incorrectly describe the density of their screens. The density is not derived from the physical size and pixel count. Some have done this for compatibility reasons; for instance, the original Samsung Galaxy Tab (released before Honeycomb, therefore not technically "tablet ready") reports itself as HDPI so that graphics and layouts are selected to make it use the screen more like a phone.
In regards to your layouts, if you have a decent default (in res/layout/) this will be chosen if no more specific layouts are available (e.g. res/layout-land/ or res/layout-large/). Keep in mind that each of the view ids that you reference in code must be available in all layouts. Keep them all up to date with each other or you will end up with inconsistent behaviour.
If you're diligent about making graphics for at least the main three densities (ldpi, mdpi, and hdpi) then you should not see over-large icons except where the screen is physically smaller than your layout expects it. Also, use dp in your layouts instead of px.
Perhaps the good start to identify the problem is to check the Application Error Reports
in your android market publisher account.
Click on Erros(2) just next your app in the apps listing.

Android muliple screen support?

I have to design an application which to support under three resolution. for that i use the code in manifest
and also create three folder layout , layout-large, layout-small for supporting three resolution, correspondingly i put the different resolution of image in drawable-hdpi ,drawable-ldpi ,drawable-mdpi , but whenever i run the app in different resolution it going to take low resolution image instead of different resolution i use.
I don`t know where i made the mistake, whether i have to add some code in layout xml or not. I also search the android developer forum and i do the application design as they insist.
Any one suggest some idea to achieve this.Thanks
There are two things you could check: have you set the minimum SDK version of your app to use version 4 (Android 1.6) support for this started?
Secondly, the layout-large and layout-small folders are designed for different sized screens (think tablet vs phone), and not resolution. If you're changing the resolution (DPI) of the device, you'll need to use layout-hdpi, layout-ldpi etc.
Further, if it's only the images you're changing, you should be placing the different images in drawable-hdpi, drawable-ldpi etc, and not layout-xxxx. If on a supported device, Android will pick the image from the correct folder, so you'll only have one layout folder (or 2 if you use layout-land)
Some (or all :S) of these points are covered in this link, to another question on StackOverflow. Try to use the search function before asking a question. Also, you'll find people are more receptive to providing answers to users with higher accept percentages.
Android - layout-large folder is been ignored
Edit: for multiple screen support, also look at Fragments to better organise and fit your content for both large and small screen devices (dev.Android, worked example)

Categories

Resources