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
}
Related
I have a viewpager with imageviews and I have set it like this:
mViewPager.setPageMargin((int) getActivity().getResources().getDimension(R.dimen.view_pager_margin));
<dimen name="view_pager_margin">-250dp</dimen>
Now, I've created the following dimens files:
But, when I start Nexus 5X and Nexus 6P emulators they both share the dimens.xml(xxhdpi) file and the images don't look good on both. What would be the best approach so my images can look as they are supposed to on every device?
According to https://design.google.com/devices/, the 5X and 6P both have dimensions of 411 dp x 731 dp. However, the 5X is an xxhdpi device, whereas the 6P is an xxxhdpi device, so they're actually using different dimens.xml files.
I would recommend defining your dimens.xml based on actual screen dimensions rather than screen density. For example, a dimens-w400dp.xml would apply to both devices.
https://developer.android.com/guide/practices/screens_support.html#NewQualifiers
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 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
I have values-xxhdpi folder having dimens.xml file, i set the font size 34sp in nexus 5. When I put this on the samsung s5 the font looks very small. Is there any possible way of having the font size look the same (size wise) on both devices?
android:textSize="#dimen/font_size_34sp"
I have find screen size difference
Nexus5 4.9"
S5 5.1"
Provide me generic solution, if possible I want to be able to do this in XML.
You could have a method at run time (onCreate) to get the screen dimensions then based on that re-size the font dynamically.
As different phones have the same DPI but different screen dimensions.
Please also view this
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".