I have been struggling with this problem about a week and can not figure out how to make it work. I have some views on a screen. And one values\dimens.xml(sw320dp-xxhdpi) resource file. Also I have nexus 5.2 1080*1920 420dpi and nexus 5.0 1080*1920 xxhdpi. The layout appears differently on both screens. How to make it display the same on each device?
What resource file should I add (if it is any)?
How to add for example values\dimens.xml(1080*1920 420dpi)?
I think your layout is simply built as poorly scaling. Unless you have some very specific use case, you need to make sure your layout fills the area it is provided with regardless.
As for the resource folder, if you want to make sure the same layout file is used on large screens, it is enough to put it in the folder layout-sw360dp. If you have xxhdpi devices with the resolution 1080x1920, Android will select the same file for both since the smallest side will be exactly 1080 / 3 = 360 density-independent pixels.
How to make it display the same on each device?
In general it's impossible for all Android devices. I think best solution - using VectorDrawable or SVG format and scale vectors for each device.
Related
I have a strange bug on Samsung Galaxy Tab E (Nougat 7.0 API 24): I have 2 layout directory (layout and layout-sw600dp) when I change the "Screen Zoom" on the "Settings" to "Huge" the device for some reason is taking the XML from the "layout" directory and not from the "layout-sw600dp", for all the others density it works perfectly except the this one.
Is there a solution for this bug?
It's not only in Galaxy devices but you can have this in any device exceeding the sw system.
So instead of making specific folders like layout-sw600 etc, I recommend you to make specific layouts using ConstraintLayout.
ConstraintLayout not only makes your layout flexible but also adjusts it's size based on the increase or decrease in Density Pixels of the devices and also saves your. Development Time. I faced a similar issue long time back and decided to use ConstraintLayout for the same.
A good codelab from Google on ConstraintLayout can be found here:
https://codelabs.developers.google.com/codelabs/constraint-layout/index.html?index=..%2F..%2Fio2018#0
Hope it helps. Good luck.
The system will use the one which is closest to (without exceeding) the device's smallestWidth, but when Screen Zoom set to Huge, the smallest width of device exceeds 600dp.
And your layout files only have two folders (layout and layout-sw600dp), so finally the system choose the layout folder.
I've got a Pixel XL and I like to keep the screen size set to small. However, the default size for the Pixel is defined by Google as xxxhdpi, so my increasing the dpi isn't "detected" so no scaling is triggered.
When making an app, I can't seem to create a folder called xxxxhdpi or xxlarge, so I'm kind of at a loss as to how to define the layout for the higher DPI.
I found a resource suggesting to simply define the dpi, i.e. calling the folder 720dpi, but Android Studio throws a compile error if I do that.
Does anyone have any idea how I can make the app show up correctly on my phone?
Can you make minmap-xlarge resource folder? but not sure whether Pixel xl device will read from it. Here is the screenshot.
I am developing app.I have only layout folder with xml files,it is showing properly in more pixel screen ,but when i see my app in less pixel screen the text is big not same as more pixel screen As per android developer site, I came across layout-sw320dp ,layout-sw480dp. So I have added the xml files into layout-sw320dp,layout-480dp and made changes like text size and margin,then when i run them with sw-320dp in less pixel screen i can see text size same as more pixel screen,but when i run with sw-320dp the same in more pixel screen, the text is small ,it is taking layout from only sw320 actually it should take from layout folder.I d'not know where I am wrong can any one tell me.
screens with only layout folder
[![screen in less pixel density[![screen with more pixel][1]][1]][2]
screens with layout-sw320sp
[![screen in less pixel [![screen with more pixel density][3]][3]density][4]][4]
[1]: http://i.stack.imgur.com/6rTNw.png
[2]: http://i.stack.imgur.com/uHRkx.png
[3]: http://i.stack.imgur.com/qhcmk.png
[4]: http://i.stack.imgur.com/Z5PE0.png
You are not supposed to pick what resource size is shown, android does that depending on the device used at runtime. Your job is to set the resource in the correct folder for example res/layout/mylayout.xml and res/layout-sw480dp/mylayout.xml res/layout-sw320dp/mylayout.xml sw is smallest width of screen, 320 is a number, dp can be thought of as pixels. This concept of putting resources in folders with special names and allowing android to pick the most sutable special name/folder for the job works for any resource. Strings/languages, images/for device screen size,night/day,orientation-|.
I'm developing for android wear, and instead of using 2 different layouts (one for rect, and one for round), can I just use resource qualifiers instead?
For example, I have a layout file: activity_main.xml. It references pizza.png. can I make it so that the round watch (320x320) pulls the image from drawable-w320dp while the rectangle watch (280x280) pulls the image from drawable-w280dp?
Thanks
Update:
There are specific qualifiers as of API 23 (-round and -notround). Check out the official blogpost.
Original Answer:
No, I don't think so. There are no specific qualifiers for form factor (such as -round or -square) and the screen size in pixels is not the same across all square devices. For example, the Samsung Gear Live is 320x320 too.
Moreover, these values are in pixels, not dp as in your example, but this is a minor point.
You should use -nodpi for backgrounds, and -hdpi for rest of graphic files (for now, it might change in the future). There are no shape specific folders as that should be handled in StubView or by fitting content in by using for example BoxInsetLayout.
I have 2 devices, a 1024x600 7" tablet hdpi running Gingerbread and a hub attached to a touchscreen which is 1920x1008 22" in size, hdpi running ICS. The Android OS seems to consider both as "large" (240dp).
So, they have the same actual density (240dpi), same generalized density (hdpi), same generalized size (large) but different actual size (7" vs 22")
The text and spacing dimensions that I specify for my layout work great on the 22", but then on the 7" they look enormous and dont fit on the screen.
I've tried using dp and sp, no difference as I think the problem is that Android sees these things as the same size / density. Does anyone have any recommendations on how I can be able to scale sizes appropriately?
This program wil also eventually need to be supported on a 4.5" handheld as well.
Thanks in advance.
Sorry, my previous answer was completely wrong = )
Ideally, you should be able to design for the 7" tablet and have your layout scale up to the TV. But if that doesn't work you should be able to use something like layout-sw1008dp. The "sw" prefix allows you to specify the minimum dimension of the smallest side of the screen - so in the case of a TV, the height.
I am also facing such problem in my application. But i found a good solution for this.
I have only one layout for tablet and directory name is layout-sw600dp.
Now, when part came to height and width problems, I have created several different values directory in which i place dimensions and font size and other stubs. So there will be no constant value in layout of tablet screen.
androd:layout_width:"60dp" // i drop this scenario
androd:layout_width:"#dimen/tab_width" // i used this scenario
and your values directory name will be like
values-xlarge
values-large
All the values will be fetched from your values directory. It will not create different layout, but one layout can be used multiple times.
See my stack answer which may help you.