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
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.
I have the following structure of layouts for a particular activity:
Now when I check the specs of Micromax Funbook over here I get to know it is a 7 inch tab with resolution of 400X800
The docs state that for seven inches tablest I should use sw-600dp qualifier. However I am puzzled as the concerend tablet is taking layouts from sw-480dp folder.
When I test on a Nexus 5 device which is 4.95 inches and thus should either refer to sw-480 or sw-600 I see it takes the layout from layout folder without any size qualifier(mock_layout.xml - without qualifiers)
What could be wrong? What is the proper way of doing this?
By following this tutorial, I created 3 different layout folders (over default layout folder):
layout-large
layout-small
layout-xlarge
In this way, some screens do not fit as I want.
For example, Nexus s, Galaxy Nexus and Nexus 4 preview seem to use the default layout, but it doesn't fit well.
Should I create other layout folders, for these devices (and others that I'm maybe forgetting)?
Nexus s, Galaxy Nexus and Nexus 4 are all "normal" sized devices (or large, i'm not sure). So the behaviour you're getting is "correct".
Have you tried to specify layouts according to the smallest width?
Something like layout-sw480dp, this should target the devices you want.
I would like to create a layout specifically for a device having the following display specification
480 x 800 pixels, 4.3 inches (~217 ppi pixel density)
The following is the closest thing i could get setting to
However the resulting layout is quiet different with the one i get
This is what it looks like in Eclipse
This is what it looks like in Device (Genymotion)
I have set up the following layout folder:
layout (baseline)
layout-xhdpi
layout-hdpi
Can anyone help me with this?
note: somehow when i use layout-large, layout-normal, and so on the respective layout does not loaded correctly. It always revert back to baseline layout.
You should read Supporting Multiple Screens. Layout (-large, -normal, etc) are determined by the physical size of the device (in inches). the drawable resources (-xhdpi, -hdpi, -mdpi, etc) are determined by the screen resolution.
If you want to clone the device (480x800, 4.3 in) than the emulator will use the layout-normal (or baseline) and the drawable-hdpi resources (if I did the math correctly)
If you are still unsure which layout will be loaded you can check during runtime using something like this:
if ((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_LARGE) {
// on a large screen device ...
}
I've developed an app that was supposed to target both the Galaxy Nexus and the Galaxy S3. Both have 720 x 1280 screen resolutions and I have only used 'dp' values in my app. The resources exist in the 'layout-xhdpi' and the 'drawable-xhdpi' folders. Layout looks perfectly fine on the Nexus, but the padding values (in dp) is slightly off on the S3. I assume its because of the bigger screen size on S3 and difference in density.
How can I create a separate folder for Nexus and S3 so I can take into account the different screen sizes?
Use this scheme:
For same layout landscape and portrait layout-sw360dp
Only for landscape layout-sw360dp-land
Only for portrait layout-sw360dp-port
I try to say you can use the before clasification creating folders with theses names. The layout located into are loaded in the Galaxy S3 - WXGA720. This is a way for disting the layout for this type of device. Its necesary Android 4.0+.
I use sw360dp-long which the system will use for the GS3 and I use sw360dp for the Galaxy Nexus.
Nexus 4: use sw384dp (768x1280)
Samsung S3: use sw360dp (720x1280)
It should be noted that both do fall into the sw360dp bucket, but some developers might need to make things pixel perfect, so the 384 folder might be needed but should be avoided if you can design a more flexible layout using LinearLayout and "weight" instead of hardcoding dp units.
You can get the device model and can set layout.
As following you can get model
String phoneModel = android.os.Build.MODEL;
if(phoneModel.equals("ABC")) {
// SET Ralated Layout
} else if(phoneModel.equals("XYZ")) {
// SET Ralated Layout
}