Android Layout: same device size family, different real device sizes - android

Just a quick question:
My application should work both for my device (Galaxy Ace - 320 x 480 - "Normal" screen size family) and for the Galaxy Nexus (720 x 1280 - "Normal" screen size family).
I wrote two layouts in two different folders: layout and layout-sw600dp.
Unfortunately the Galaxy Nexus keep to choose the xml definition in the "layout" folder instead of "layout-sw600dp" one.
How can I solve this?
Thank you in advance.

(Thanks to #Class Stacker)
For everyone who has the same issue: put the layout xml file for the Galaxy Nexus in a folder called "layout-xhdpi".

Related

Changing the orientation switches the layout used when designing

Wondering if anyone has ran in to this.
I have created layout folders with 5 resource qualifiers.
sw320dp
sw480dp
sw600dp
sw720dp
sw800dp
I also have 5 drawable folders with resource qualifiers from mdpi through xxxhdpi.
My goal is to have my application function on all devices (minus small) with smallest width of 320 and any density.
I am 90% of the way there and have ran in to an issue which I have been unable to resolve. My guess is that I have an issue with resource qualifier precedence , but that is only a guess.
The issue I am running in to is this. I can double-click on ANY of my layouts in any of the different layout folders and it will bring up the layout using an appropriate device within Android studio designer given the sw<n>dp layout that I selected. For example, if I double-click on my main_activity layout that is in the sw600dp folder, it opens using the 7" tablet and everything is good. This holds true for every layout I have in every layout folder, with the exception of ONE layout within my layout-sw480dp folder.
When this particular layout is opened, it opens up in Portrait mode via the Nexus 4, when it should have launched one of the sw480 devices instead. If we look at the specs of the Nexus 4, it is as follows.
768 x 1280 / hdpi
So, this means that the smallest width of this device would be 768 / 2 = 384, which falls in to the sw320dp bucket.
If I then select one of the sw480dp devices, such as the Nexus 6p, which has the following specs, 1440 x 2560 560dpi which in turn has a smallest screen width of 1440 / 3 = 480, it opens using a layout in the sw320dp folder.
Again, this is the ONLY layout file that is doing this out of ALL of them.
If anybody has any suggestions or has ran across this type behavior in the past, I would love to hear what you did.

Choosing layout folder for supporting all devices

I got a problem related to the layout folder for some device.
So at first I had layout and layout-large folder. I only have 3 xml files for layout inside of these layouts.
layout folder has xml files with using Eclipse configuration of Galaxy Nexus 4.65" (720x1280 xhdpi)
layout-large folder has xml files using Eclipse configuration of 5.1" WVGA (800x480 mdpi)
I tested it on a small Samsung Galaxy Youth 3.3" (320x480), and it's using layout folder... I don't really understand about screen res, I read it in google doc but until now I don't really get enough of it. Google Nexus configuration looked fit for small screen so I chose it without enough understanding in resolution or screen size. Somehow, it fit well in my Galaxy Youth.
While for larger screen device I depend on layout-large folder, so I tested it with Galaxy Tab 7". It fit well too.
Problem arise when I tested it with Galaxy Note 2 and Galaxy Note 4 .. (for other devices I didn't test because I don't have them).
Galaxy Note 2 and Galaxy Note 4 seems to use layout folder not the large one (I'm sure it'll fit well in my layout-large).
I actually want 320x480 or smaller screen size devices to all use layout and any devices with larger screen should use layout-large. How to achieve that?
YOU CAN USE CODE TO SELECT YOUR DESIRED layout for specific smallest-WIDTH of DEVICE..IN
onCreate:
Configuration config = getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 480) {
setContentView(R.layout.main_activity_LARGE);
} else {
setContentView(R.layout.main_activity);
}
the Document say about ( sw NUMBER dp) format :" The exact point of this switch will depend on your particular design—maybe you need a 720dp width for your tablet layout, maybe 600dp is enough, or 480dp, or some number between these. "
so you can put in res :
res/layout/main_activity.xml
res/layout-sw480dp/main_activity.xml
Look here: http://stefan222devel.blogspot.sk/2012/10/android-screen-densities-sizes.html
There is more information about screen sizes and densities of android devices

specific 4 inch drawable layout?

I want to design a specific layout for galaxy S3 mini or any device with 4 inch screen size, now I don't want to use normal-layout because what looks perfect in other devices in normal-layout looks messy in 4 inch devices, I tried to do a layout for 480 x 800 like layout-w480dp-h800dp but it didn't work so what specific layout can I use?
Thanks in advance.

How to create different layout for Nexus 4 and similar devices? (Galaxy S4)

The question is how create a specific layout for Nexus 4 and similar devices?
4.7" diagonal
1280 x 768 pixel resolution (320 ppi)
WXGA IPS
For Nexus 4 should load the same layout that Galaxy S3
Galaxy S3
Screen Size: 4.8 inch
Screen Resolution: 1,280 x 720 pixels
And the configuration should be:
For same layout landscape and portrait layout-sw360dp
Only for landscape layout-sw360dp-land
Only for portrait layout-sw360dp-port
Other similar devices:
LG Optimus 4X HD
HTC One X+
For Galaxy S4 should also compatible and load this layout
The response was in this entry: Android S3 layout vs Galaxy Nexus layout
You can create layout directories for specific combinations. For 7" 1280 x 768 at 320 ppi it will look something like this:
layout-sw600p-xdpi-large
As #Tomer Mor mentioned, you can find a full list of available parameters here
Also, if you want to be even more specific about device parameters, take a look at this question - you can assign different layouts from code, depending on the environment.

Display issue on HTC Flyer

I have developed an application and created the xml files in different layout :
layout-large
layout-large-1024x600
layout-normal
layout-normal-480x320
layout-normal-640x360
layout-normal-640x480
layout-normal-800x480
layout-small
layout-small-320x240
layout-small-400x240
I have tested the application on five different android devices and it works ok on 4 of it. On the HTC Flyer (resolution 1024x600) the result is not ok. The icon are too little not in the right place...
In the eclipse graphical layout preview of the 1024x600 resolution, the result is ok. I don't understand why the result on the Flyer is not ok.
I have all the image in the drawable-hdpi folder.
Any help would be appreciated !
The problem was that I defined the 600x1024 7.0 display as HDPI instead of MDPI. Now it works OK.

Categories

Resources