Android device 3.2+ picks from layout-large - android

I have the following folders for layouts :
layout,
layout-large,
layout-xlarge,
layout-sw720dp
As far as I know, For Android 3.2+, if you have at least one folder that uses the new size quantifiers then it assumes that you are using these new size quantifiers everywhere and ignores any other folder that uses the old quantifiers.
Since I have one folder (i.e. layout-sw720dp) with the new quantifier, I would expect Nexus 7 to pick layouts from the default layout folder. But it is picking the layout from layout-large folder. Can someone please help me understand why?

Just add the same files you have in layout-large to layout-sw480dp or reference the layout from within there.
Anyway: As most devices below 3.0 are phones which are most likely not large nor xlarge and there are nearly no devices out there running android 3.0 or 3.1, I strongly recommend to drop layout-large and layout-xlarge completely and just stick to the new folders.

Here I found the solution to my question:
For Android 3.2+, if you have at least one folder that uses the new size quantifiers then it assumes that you are using these new size quantifiers everywhere and ignores any other folder that uses the old quantifiers.
But the way Android finds out whether you have a folder with new size quantifier is slightly different.
It checks for new size quantifier folders only equal to and below the sw of the device that it's running on.
For example, for Nexus 7 Android would look for folders in the order sw600dp, sw480dp, sw360dp, sw320dp and finally if none of those are present it picks from layout folder. sw720dp though present is not taken into consideration since it is out of range for a nexus 7 device.

Related

Android Virtual Device detects wrong screen size

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

Inflate from layout-v10 folder on a hdpi gingerbread device?

I'm having both layout folders "layout-v10" and "layout-hdpi" in my application. However, as some gingerbread(which is API Level 10) devices also are hdpi screen size, the layouts under the "layout-hdpi" folder is getting inflated. I want to force the layout from "layout-v10" folder to be inflated for all gingerbread devices even if it is a hdpi. Is there any way to do so?
I read this link http://developer.android.com/guide/practices/screens_support.html couldn't figure out what can be done to solve my problem.
to keep layouts looking good in all devices we don't provide folders like "layout-hdpi", etc.
U need to keep your resources in drawable-hdpi, drawable-xhdpi, etc. as mentioned in the android developers guide. The android system chooses the correct folder based on the screen density. This works independent of the api version you are using, the layout will look good in all api levels if you are defining your resources correctly acc. to different screen densities.

Will layout folders fix the tablet compatibility?

I read a few things about how to make your app compatible with tablets. Some say about using your code and some say about the layout folders or some about the sw600dp and sw720dp folders. I am really confused and am not 100% sure which is the most simplest way to just make it play on a tablet.
What i did is i made 3 more layout folders (large, xlarge and small, I already had the drawable classes in all sizes but i didnt change the size of the images, its in all drawables the same size) and in these 3 extra folders i copied the same files i had in the plain layout folder. So i have 4 layouts with all the xmls the same.
Will this make it compatible with tablet and fix my issue?
for Xlarge use this folder drawable-xlarge-hdpi
for large use this folder drawable-large-xhdpi
layout-large (7 inch)
layout-xlarge(10 inch) folder are used for layouts
The Simplest way to make your app adopt to different hardware configurations is using folders. The framework will do all the work for you. (tutorial)

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)

xlarge vs sw720dp screen size confusion

For reference: http://developer.android.com/guide/practices/screens_support.html
The old style size quantifiers are "deprecated":
A set of four generalized sizes: small, normal, large, and xlarge
Note: Beginning with Android 3.2 (API level 13), these size groups are
deprecated in favor of a new technique for managing screen sizes based
on the available screen width. If you're developing for Android 3.2
and greater, see Declaring Tablet Layouts for Android 3.2 for more
information.
I was hoping that devices with 3.2+ would still use resources declared in drawable-large-mdpi, or layout-xlarge, but this doesn't seem to be the case.
I have a test project that contains a layout file for each of these sizes:
layout-sw600dp
layout-720dp
layout-xlarge
layout
On a 10" Motorola XOOM running Android 4.0.x, the device picks the layout in the layout-720dp folder. If that folder doesn't exist, it picks the layout in the layout-sw600dp folder! Why doesn't it pick the layout in layout-xlarge?
Even more strange, is I have drawables in these folders:
drawable-sw600dp-mdpi
drawable-xlarge-mdpi
The 10" Motorola XOOM from above, picks the image from drawable-sw600dp-mdpi. Why doesn't it pick the drawable in drawable-xlarge-mdpi?
Should we not expect the xlarge quantifier to work at all above Android 3.2?
Does this mean I have to duplicate all assets in the drawable-xlarge-mdpi folder, into the drawable-sw720dp-mdpi folder? (To support Android 3.0, 3.1 AND 3.2+?)
Hopefully I am just missing something simple here. Please advise.
From my understanding, for Android 3.2+, if you have at least one folder that uses the new size quantifiers then it assumes that you are using these new size quantifiers everywhere. So this is the reason why it ignores layout-xlarge or any other folder that uses the old quantifiers.
With regard to backward compatibility, you'll have to use in your project both types of quantifiers. The old ones will be used for API < 3.2 and the new ones for API >= 3.2. To avoid duplication, for the layouts you can use aliases. However, for drawables, I don't know of any solution to avoid duplication.

Categories

Resources